Amar Amar - 2 months ago 12
Python Question

TypeError: fun() missing 1 required positional argument: 'link'

I am facing a basic problem and unable to resolve it. I am getting this error


TypeError: fun() missing 1 required positional argument: 'link'


If i give
self
as positional argument in call of
fun()
as
fun(self,glit)
then I an getting


Undefined Variable self


There is no indentation problem in this small function. I also tried
self.fun(glit)
But it is also giving


Undefined Variable self.


If I delete the word
self
from
def fun(self,link):
then it is also not working.
Any way out?

class myClass:

def fun(self,link):
print("fun")

glit = "http://www.google.com"
fun(glit)

Answer

The problem is that you are trying to call that code from the class. Class should only contain methods, not your logic. You should call it from outside of the class:

class = myClass()
glit = "http://www.google.com/"
class.fun(glit)
Comments