Paul Boddie <p...@boddie.org.uk> writes:

> The only way to think about this (in Python 2.x, at least) is to
> consider stream and file objects as things which only understand plain
> byte strings. Consequently, use of the codecs module is required if
> receiving/sending Unicode objects from/to streams and files.

Actually strings in Python 2.4 or later have the ‘encode’ method, with
no need for importing extra modules:

=====
$ python -c 'import sys; sys.stdout.write(u"\u03bb\n".encode("utf-8"))'
λ

$ python -c 'import sys; sys.stdout.write(u"\u03bb\n".encode("utf-8"))' > foo ; 
cat foo
λ
=====

-- 
 \      “Life does not cease to be funny when people die any more than |
  `\  it ceases to be serious when people laugh.” —George Bernard Shaw |
_o__)                                                                  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to