inheriting file object
harold fellermann
harold.fellermann at upf.edu
Wed Jul 6 13:29:18 EDT 2005
On 06.07.2005, at 18:58, Jeremy wrote:
> Hello all,
> I am trying to inherit the file object and don't know how to do it. I
> need to open a file and perform operations on it in the class I am
> writing. I know the simple syntax is:
>
> class MyClass(file):
> ...
>
> but I don't know how to make it open the file for reading/writing. Can
> anyone help me out with this?
just invoke file.__init__ inside your own init. if you don't need to do
any initializiation in myFile.__init__, just leave the method and
file.__init__ will be invoked automatically.
class myFile(file) :
def __init__(self,fname,mode="r") :
file.__init__(self,fname,mode)
for line in myFile('testfile') :
print line
- harold -
--
If your only tool is a hammer, every problem looks like a nail.
--
More information about the Python-list
mailing list