print / str / repr

Nikolai Kirsebom nikolai.kirsebom.NOJUNK at siemens.no
Tue May 18 07:48:27 EDT 2004


How do I (in a program) achieve the same result as using the print
statement (interactive).

In the interpreter:

>>> s = u "some '\xcf' text"
>>> print s
Traceback (most ....):
UnicodeError: ASCII encoding error: ordinal not in range(128)
>>> s.encode('latin-1')
"some '\xcf' text"
>>> print s.encode('latin-1')
some '¤' text
>>> `s.encode('latin-1')`
'"some \'\\xcf\' text"'

Thanks for any help.
Nikolai







More information about the Python-list mailing list