Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.

Bug? interactive echo clobbering softspace of redirected stdout?

Yametazamwa mara moja
Ruka hadi kwenye ujumbe wa kwanza ambao haujasomwa

Bengt Richter

hayajasomwa,
16 Jul 2002, 18:55:0316/07/2002
kwa
ISTM it's a bug one way or another.

Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class X:
... def __init__(self): self.s=[]
... def write(self,x): self.s.append(x)
...
>>> import sys
>>> oso=sys.stdout
>>> sox=X()
>>> dir(sox)
['__doc__', '__init__', '__module__', 's', 'write'] <<--There's no .softspace yet.
>>> sys.stdout=sox
>>> dir(sox) <<--This seems to create one before doing dir()
>>> print 'sox ss=%s'% (sox.softspace,), <<--This should leave softspace set IMO. Interactive EOL
>>> print 'sox ss=%s'% (sox.softspace,), should reset sys.__stdout__.softspace, not sox.softspace
>>> def foo():
... print 'from foo: sox ss=%s'% (sox.softspace,), <<-- these will go out with only one EOL below
... print 'from foo: sox ss=%s'% (sox.softspace,),
...
>>> foo() <<-- single interactive EOL doesn't kill first softspace
>>> sys.stdout=oso
>>> sox.s
["['__doc__', '__init__', '__module__', 's', 'softspace', 'write']", '\n', 'sox ss=0', '\n
', 'sox ss=0', '\n', 'from foo: sox ss=0', ' ', 'from foo: sox ss=1', '\n']

Or, a hand-edited grouping:

[
"['__doc__', '__init__', '__module__', 's', 'softspace', 'write']",'\n', <<--from dir(sox)
'sox ss=0', '\n', <<--from 1st print 'sox... -- should have left softspace set for next print
'sox ss=0', '\n', <<--from 2nd print 'sox... -- but it got clobbered
'from foo: sox ss=0', ' ', 'from foo: sox ss=1', '\n' <<-- from foo(), note softspace not clobbered.
]

Looks to me like interactive typing echo should operate on the softspace attribute of the output
it's going to (sys.__stdout__.softspace ?), and not sys.stdout.softspace, unless they're the same.

Or else interactive echo characters ought to be teed/copied to sys.stdout to make the softspace action
consistent with modifying sys.stdout.softspace. I prefer the former.

Regards,
Bengt Richter

Ujumbe 0 mpya