How does Python get the value for sys.stdin.encoding?

RG rNOSPAMon at flownet.com
Wed Aug 11 21:21:43 EDT 2010


I thought it was hard-coded into the Python executable at compile time, 
but that is apparently not the case:

[ron at mickey:~]$ python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys;print sys.stdin.encoding
UTF-8
>>> ^D
[ron at mickey:~]$ echo 'import sys;print sys.stdin.encoding' | python
None
[ron at mickey:~]$

And indeed, trying to pipe unicode into Python doesn't work, even though 
it works fine when Python runs interactively.  So how can I make this 
work?

Thanks,
rg



More information about the Python-list mailing list