inherit from file and create stdout instance?

MisterPete pete.losangeles at gmail.com
Tue May 15 23:22:29 EDT 2007


> 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
>             super(Output, self).write(string)

I may have to just accept name as a string or as a file object so that
I can still provide the same interface as a file object.  It'll just
store and use a separate file object when it needs to handle writing
to stdout and sterr.  This way it should always be able to be used in
place of a file object.

err, and again, not that it matters but in the code above verbosity
should of course get the value passed in, not 1 :/




More information about the Python-list mailing list