I have file called im.py
which contains a couple of functions and several classes. The first function and class are failing with
TypeError: \'list\'
You cannot use the same name for both a method and an attribute; methods are just special kinds of attributes. Your class may have a user()
method, but by setting the attribute user
on the instance, Python will find that instead of the method when you try to access b.user
:
>>> type(b.user) # no call, just the attribute
You'll have to rename either the method or the attribute to not conflict. You could use a leading underscore for the list attribute, for example:
class FirstClass:
def setdata_user(self):
self._user = getdata_user()
def displaydata_user(self):
print(self._user)
def user(self):
u = self._user[0]
return u
def gids(self):
g = self._user[1]
return g
def home(self):
h = self._user[2]
return h