Help! Cannot open a file in a class
ouj
ouj at aludra.usc.edu
Mon Mar 3 23:47:40 EST 2003
Hi,
I am new to Python. I write a class that opens a file and reads the
data from the file.
class Cvdoc:
def __init__(self):
......
fd = file('vdoc.dat', 'wr')
print dir(fd)
fd.readlines()
I used the following code to use this class:
a = Cvdoc()
And I got the following response:
$ python vdoctest.py
['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__',
'__init_ ...... ritelines', 'xreadlines']
Traceback (most recent call last):
File "vdoctest.py", line 12, in ?
a = Cvdoc()
File "vdoctest.py", line 8, in __init__
fd.readlines()
IOError: [Errno 9] Bad file descriptor
I can get access to the attributes of fd, such as fd.mode. However, I
cannot invoke the methods associated with fd, such as fd.read(), etc.
Can any one tell me help me out? Thanks a lot!
Best regards,
Jingzhao
More information about the Python-list
mailing list