subclassing "file"
James Henderson
james at logicalprogression.net
Mon Jan 19 11:29:27 EST 2004
On Monday 19 January 2004 4:14 pm, Uwe Mayer wrote:
> Hi,
>
> when extending a build in class, what does the constructor __init__(...)
> have to return?
> and how does the constructor call its base-class construtor? (or is this
> done automatically?)
>
> I want to derive from "file" to create a class that reads record from a
> binary file:
>
> class myFile(file):
> def __init__(self, filename, mode="r", bufsize=-1):
> ....?...
>
> just calling the basename and the constructor does not work:
> >>> f = myFile("testfile")
> >>> f
>
> <closed file '<uninitialized file>', mode '<uninitialized file>' at ...>
>
> What am I missing?
You don't show the second line of you __init__ method. It should be:
file.__init__(self, filename, mode, bufsize)
James
--
James Henderson, Logical Progression Ltd.
http://www.logicalprogression.net/
http://sourceforge.net/projects/mailmanager/
More information about the Python-list
mailing list