Anti-poking lobby (was:Re: [Types-sig] type declaration syntax)
John Machin
sjmachin@lexicon.net
Fri, 31 Dec 1999 08:59:26 +1000
Skip said:
>
> skaller> I.e. TWO bans fix most problems. The ban on module level
> skaller> rebindings is a significant restriction.
>
> I'll say. The common idiom for trapping stdout or stderr is to rebind
> sys.stdout/stderr to a file-like object. How would that be accomplished
> in such a straightforward way if module-level rebindings are disallowed?
>
sys.stdout = "you lose"
is a bit too straightforward for my liking.
Once we have banned poking from outside a module, can't we fix the
presumably-few cases of missing-but-required functionality by supplying
functions? For example,
previous_stdout = sys.divert_stdout(new_stdout_file-like_object)
[default argument is original stdout]
with maybe some checking as determined by the module's "owner" [is it
truly file-like?], and maybe some extra functionality e.g.
sys.divert_stdout("my_stdout.log")
# interprets string as name of file; appends if existing, else creates