Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

E1120:No value for argument in constructor call

I'm pretty new to Python Classes, and I wanted to test a simple code:

class information:
  def __init__(self,fname,lname):
    self.fname = fname
    self.lname = lname
  def first(self):
    print ("First name :", self.fname)
  def last(self):
    print ("Last name :",self.lname)
firstname = information("Name")
lastname = information("Test")

However, Pylint gives me an error:

E1120:No value for argument 'lname' in constructor call (11,13)
E1120:No value for argument 'lname' in constructor call (12,12)

What's the problem here? I think I have defined lname as 'self.lname = lname"

like image 913
Plazmican Avatar asked Oct 28 '25 07:10

Plazmican


1 Answers

__init__() is expecting two positional arguments, but one is given.

See your __init__():

def __init__(self,fname,lname):

You should create object of the class and use this object to call functions of the class, like so:

class information:

  def __init__(self,fname,lname):
    self.fname = fname
    self.lname = lname

  def first(self):
    print ("First name :", self.fname)

  def last(self):
    print ("Last name :",self.lname)

obj = information("Name", "Test")   # <-- see two arguments passed here.
firstname = obj.first()
lastname = obj.last()

# First name : Name
# Last name : Test

Note: When you create an object of a class, the class's constructor is automatically called. Arguments you pass while creating object must match with the number of arguments in the constructor.

like image 109
Austin Avatar answered Oct 29 '25 21:10

Austin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!