[code.view]

[top] / python / PyMOTW / codecs / codecs_stdin.py

     #!/usr/bin/env python
     # encoding: utf-8
     #
     # Copyright (c) 2010 Doug Hellmann.  All rights reserved.
     #
     """Printing unicode text to sys.stdout.
     """
     #end_pymotw_header
     
     import codecs
     import locale
     import sys
     
     # Configure locale from the user's environment settings.
     locale.setlocale(locale.LC_ALL, '')
     
     # Wrap stdin with an encoding-aware reader.
     lang, encoding = locale.getdefaultlocale()
     sys.stdin = codecs.getreader(encoding)(sys.stdin)
     
     print 'From stdin:', repr(sys.stdin.read())
     

[top] / python / PyMOTW / codecs / codecs_stdin.py

contact | logmethods.com