[Tutor] quick question to open(filename, 'r') vs. file(filename, 'r')

spir denis.spir at free.fr
Tue May 5 12:41:21 CEST 2009

Le Tue, 5 May 2009 00:41:39 +0100,
"Alan Gauld" <alan.gauld at btinternet.com> s'exprima ainsi:

> > Backwards compatibility.  The file type was introduced in python 2.2, 
> > before which there was open.  
> And file has been removed again in Python v3....
> In fact open is now an alias for io.open and no longer simply returns
> a file object - in fact the file type itself is gone too!
> A pity, there are cases where I found file() more intuitive than
> open and vice versa so liked having both available. The fact that it
> looked like creating an instance of a class seemed to fit well
> in OO code.

Same for me. It makes files an exception in the python OO system. Conversely, I have always considered open(), rather than file(), a flaw.
(But there are numerous things on which I have a different point of view than the majority of pythonistas ;-)

la vita e estrany

More information about the Tutor mailing list