inherit from file and create stdout instance?

2007-05-15 Thread MisterPete
How can I inherit from file but stil create an instance that writes to stdout? --- I'm writing a file-like object that has verbosity options (among some other things). I know I could just set self.file to a file object rather than inheriting from file. I started with something like thi

Re: inherit from file and create stdout instance?

2007-05-15 Thread MisterPete
> Your code works for me: > > import sys > > class Output(file): > def __init__(self, file=sys.stdout, verbosity=1): > self.verbosity = verbosity > self.file = file > > def write(self, string, messageVerbosity=1): > if messageVerbosity <= self.verbosity: >

Re: inherit from file and create stdout instance?

2007-05-15 Thread MisterPete
On May 16, 1:50 pm, 7stud <[EMAIL PROTECTED]> wrote: > >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 > se

Re: inherit from file and create stdout instance?

2007-05-15 Thread MisterPete
> class Output(file): > def __init__(self, name, mode='w', buffering=None, verbosity=1): > super(Output, self).__init__(name, mode, buffering) > self.verbosity = verbosity > > def write(self, string, messageVerbosity=1): > if messageVerbosity <= self.verbosity >

print bypasses calling write method for objects inheriting from file?

2007-05-30 Thread MisterPete
I created an object that inherits from file and was a bit surprised to find that print seems to bypass the write method for objects inheriting from file. An optimization I suppose. Does this surprise anyone else at all or am I missing something? import sys class FromObject(object): def wri

Re: print bypasses calling write method for objects inheriting from file?

2007-05-30 Thread MisterPete
On May 31, 5:54 am, Peter Otten <[EMAIL PROTECTED]> wrote: > Gabriel Genellina wrote: > > En Wed, 30 May 2007 04:24:30 -0300, Peter Otten <[EMAIL PROTECTED]> > > escribió: > > >>> I created an object that inherits from file and was a bit surprised to > >>> find thatprintseems to bypass the write me