print >> to a derived file

iu2 israelu at elbit.co.il
Tue Jan 15 06:07:47 EST 2008


On Jan 15, 12:44 pm, "Ben Fisher" <jamon.... at gmail.com> wrote:
> This might have something to do with the class being derived from file.
>
> I've written it so that it doesn't derive from file, and it works.
>
> class File_and_console():
>         def __init__(self, *args):
>                 self.fileobj = open(*args)
>         def write(self, s):
>                 self.fileobj.write(s)
>                 print s,
>
> f = File_and_console('testout.tmp','w')
> f.write('hello')
> print >>f,'hello',
>

Thanks, but that's what I tried first. Then I though it would be nice
if I could just inherit from 'file' and implement this with less code.



More information about the Python-list mailing list