By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,965 Members | 1,631 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,965 IT Pros & Developers. It's quick & easy.

print / str / repr

P: n/a
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


Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Nikolai Kirsebom wrote:
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"'


You mean you want to print/write/store the exact line '"some \'\\xcf\'
text"' ?

s = u"some '\xcf' text"
s = `s.encode('latin-1')`
print repr(s.encode('latin-1')) # prints '"some \'\\xcf\' text"'

Is this what you're looking for?

-- Vincent Wehren
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.