[Tutor] Odd AttributeError
Lloyd Kvam
pythontutor@venix.com
Wed May 21 11:18:02 2003
The secret could be in the lines you left out. file is not a good
variable name since it is also a python type. Your code works:
(i changed file to filex)
class ID3:
def __init__(self, filex, name='unknown filename', as_tuple=0):
print 'printing as_tuple:', as_tuple
print 'defining self.as_tuple . . .'
self.as_tuple = as_tuple
print 'printing self.as_tuple: ', self.as_tuple
filex = file(r'c:\autoexec.bat','rt')
ID3(filex)
>>> printing as_tuple: 0
defining self.as_tuple . . .
printing self.as_tuple: 0
Neil Hodge wrote:
> All:
>
> I have the following code:
>
> def __init__(self, file, name='unknown filename', as_tuple=0):
> .
> .
> .
> print 'printing as_tuple:', as_tuple
> print 'defining self.as_tuple . . .'
> self.as_tuple = as_tuple
> print 'printing self.as_tuple: ', self.as_tuple
>
> and the following output:
>
> printing as_tuple: 0
> defining self.as_tuple . . .
> printing self.as_tuple:
> Traceback (most recent call last):
> File "./id3-tagger.py", line 93, in ?
> main()
> File "./id3-tagger.py", line 68, in main
> id3info = ID3(file)
> File "./ID3.py", line 211, in __init__
> print 'printing self.as_tuple: ', self.as_tuple
> AttributeError: ID3 instance has no attribute 'as_tuple'
>
> So, why does self.as_tuple not exist right after I defined it? Thanks.
>
> Neil
>
>
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
--
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358
voice: 603-443-6155
fax: 801-459-9582