inherit from file and create stdout instance?

7stud bbxx789_05ss at yahoo.com
Tue May 15 21:50:23 EDT 2007


>but it is frustrating me that if I try to inherit from file it
>works fine for regular files

I don't think that is correct characterization at all.  What really
happens is that when you inherit from file, your class works when you
send the __init__ method a string, i.e. a filename. sys.stdout is not
a string.  Presumably, when you have a file object like sys.stdout
already, you don't need to turn it into a file object, and therefore
file's init() method is not defined to accept a file object.

>Is it just a bad idea to inherit from file to
>create a class to write to stdout or am I missing something?

It seems to me that the very nature of a file object is to read and
write to itself.  Yet, in some cases you want your file object to be
able to write to another file object.   Why would you want your object
to be a file object if you can't use any of its methods?




More information about the Python-list mailing list