Newbie: Capture output of compile_dir

Bengt Richter bokr at oz.net
Tue Jul 16 18:10:38 EDT 2002


On 16 Jul 2002 02:35:28 GMT, bokr at oz.net (Bengt Richter) wrote:
[...]
>
>A quick experiment:
> >>> class X:
> ...     def __init__(self):
> ...         self.s = []
> ...         self.softspace=0
> ...     def write(self,x): self.s.append(x)
> ...
[...]
> >>> sox=X()
> >>> sys.stdout = sox
> >>> print 'hello',;sys.stdout.softspace=0;print 'hello'
> >>> print 'hello',;print 'hello'
> >>> sys.stdout = orig_so
> >>> sox.s
> ['hello', 'hello', '\n', 'hello', ' ', 'hello', '\n']
>
>Nope, seems to be looking at original sys.stdout.softspace
Oops, not so: sys.stdout.softspace=0 was effectively sox.softspace=0 there,
so it seems to be using it if it's available (actually it creates it if not),
but the bug is that either interactive echo characters should be teed/copied out
to a redirected stdout *OR* interactive echo should not touch redirected stdout's
softspace. ISTM the latter is more correct.

>irrespective of redirection. And I'm still not sure that
>third line is right. Why should the interactive echo to the next
>line make a difference to softspace when stdout is re-directed?
>Or is that what does it? It seems like a bug someplace...
It still seems so to me, so I will post this under a bug heading.

Regards,
Bengt Richter



More information about the Python-list mailing list