print, softspace, and stdout -- Newbie

Niels Diepeveen niels at endea.demon.nl
Thu May 25 14:14:56 EDT 2000


Brandon Irons schreef:

>   Since the softspace attribute was made writeable, it seems to me
> there must be a way to get this output using print and softspace.
> What is it?

print 'a',
sys.stdout.softspace = 0
print 'b'

I don't think the softspace attribute is really intended to be used this
way. The print statement uses it to keep track of whether the next item
printed is at the start of a line (softspace == 0) or after a previous
item (softspace == 1), so every print statement resets softspace.

> 
>   My second question is: In that last code snippet, how would I go
> about re-opening stdout?

There is no general way to reopen a file after you close it, because it
might not even exist anymore. It wouldn't do what you want anyway, if
that's any comfort.

-- 
Niels Diepeveen
Endea automatisering




More information about the Python-list mailing list