AttributeError - a dumb question
Stidolph, David
stidolph at origin.ea.com
Tue Jul 6 11:49:35 EDT 1999
You need to change the assignment of x to include the self paremter:
class F:
def __init__(self):
self.x = self.Krylys()
def KryLys(self):
l = [1,2,3,4,5]
return l
Hope this helps,
David Stidolph
-----Original Message-----
From: Johann Spies [mailto:jhspies at futurenet.co.za]
Sent: Tuesday, July 06, 1999 10:22 AM
To: Python-poslys
Subject: AttributeError - a dumb question
Why does the following code produce an attribute error?
class F:
def __init__(self):
x = self.Krylys()
def KryLys(self):
l = [1,2,3,4,5]
return l
l = F
print dir(l)
print hasattr(l, 'x')
print hasattr(l,'Krypos')
print l.x
What I do not understand is that the output from this code looks like
this:
['KryLys', '__doc__', '__init__', '__module__']
0
0
Traceback (innermost last):
File "<stdin>", line 14, in ?
AttributeError: x
'Krylys' according to dir(l) is an attribute. Why does
hasattr(l,'Krypos') report that it is not?
Johann
--------------------------------------------------------------------------
| Johann Spies Windsorlaan 19 |
| jhspies at futurenet.co.za 3201 Pietermaritzburg |
| Tel/Faks Nr. +27 331-46-1310 Suid-Afrika (South Africa) |
--------------------------------------------------------------------------
"Ask, and it shall be given you; seek, and ye shall
find; knock, and it shall be opened unto you."
Matthew 7:7
More information about the Python-list
mailing list