Again: Please hear my plea: print without softspace

Stephen Horne steve at ninereeds.fsnet.co.uk
Fri Mar 5 10:17:51 EST 2004


On Fri, 05 Mar 2004 08:50:50 GMT, m.bless at gmx.de (Martin Bless) wrote:

>[Stephen Horne <steve at ninereeds.fsnet.co.uk>]
>
>>Easy solution - write your extender such that it takes the original
>>file in the constructor...
>>
>>  sys.stdout = ExtendedFile (sys.stdout)
>
>
>Hhm,
>
>>>> import sys
>>>> class MyFile(sys.stdout):
>...     pass
>...
>Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
>TypeError: file() argument 2 must be string, not tuple
>>>>
>
>what do you mean?
>
>mb - Martin Bless

I think I was being stupid. The stuff about 'constructor' and
'inheritance' seemed right when I hadn't thought it through, of
course. I was intending inheritence from the file class, but since
when do you specify a particular instance to 'inherit' from in the
constructor???

Probably I need a brain test!

The obvious alternative is to try to add an extra method to
sys.stdout, but this doesn't work out - I assume the dictionary of
attributes for file has been fixed.

Replacing sys.stdout.write doesn't work - how does the replacement
method call the original write once it has been overwritten.

Probably the nearest equivalent is to make a wrapper class, and
perhaps a factory function to create instances wrapping existing
files. Unfortunately, there isn't a UserFile class to make this
easier.


-- 
Steve Horne

steve at ninereeds dot fsnet dot co dot uk



More information about the Python-list mailing list