Python 3.2 has some deadly infection

Chris Angelico rosuav at gmail.com
Thu Jun 5 19:39:54 EDT 2014


On Fri, Jun 6, 2014 at 9:30 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
> Steven D'Aprano <steve+comp.lang.python at pearwood.info>:
>
>>> "Can be replaced" by who? By the Python developers? By me? By random
>>> library calls?
>>
>> By you. sys.stdout and friends are writable. Any code you call may
>> have replaced them with another file-like object, and you should
>> honour that.
>
> I can of course overwrite even sys and os and open and all. That hardly
> merits mentioning in the API documentation.
>
> What I'm afraid of is that the Python developers are reserving the right
> to remove the buffer and detach attributes from the standard streams in
> a future version. That would be terrible.
>
> If it means some other module is allowed to commandeer the standard
> streams, that would be bad as well.
>
> Worst of all, I don't know why the caveat had to be there.
>
> Or is it maybe because some python command line options could cause
> buffer and detach not to be there? That would explain the caveat, but
> still would be kinda sucky.

It's more that replacng sys.std* is considered reasonably normal
(unlike, say, replacing sys.float_info, which would be a weird thing
to do); and you could replace them with something that doesn't have
those attributes. If you're running a top-level script and you never
import anything that changes the streams, you should be able to depend
on those always being there.

ChrisA



More information about the Python-list mailing list