[Tutor] quick question to open(filename, 'r') vs. file(filename, 'r')
Lie Ryan
lie.1296 at gmail.com
Tue May 5 08:02:37 CEST 2009
Alan Gauld wrote:
> 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.
But having both of them is a violation of "There should be one-- and
preferably only one --obvious way to do it."
I think python's duck typing culture makes it very rare that you want to
test whether a file is an impostor.
More information about the Tutor
mailing list