[Python-porting] porting builtin file type to python3

Benjamin Peterson benjamin at python.org
Tue Jan 20 02:14:21 CET 2009


On Mon, Jan 19, 2009 at 5:50 PM, Bernhard Leiner
<mailinglists.bleiner at gmail.com> wrote:
> Hi,
>
> I have a custom file type that looks more or less like this:
>
> class myfile(file):
>
>    def __init__(self, name, mode):
>        super(myfile, self).__init__(name, mode)
>        self.write('file header...\n')
>
> And I'm pretty sure that porting this class to python3 will result in
> something like:
>
> import io
>
> class myfile(io.FileIO):
>
>    def __init__(self, name, mode):
>        super(myfile, self).__init__(name, mode)
>        self.write('file header...\n')

2to3 would be quite happy to convert use of the file class to
io.FileIO if this was the right thing to do in 99.8% of all cases.
However, in 3.0, IO has been restructured quite a bit, and FileIO is
just a bare bones binary reading and writing class. Therefore you will
have to do something like John suggested.




-- 
Regards,
Benjamin


More information about the Python-porting mailing list