print / str / repr

N

Nikolai Kirsebom

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

In the interpreter:
Traceback (most ....):
UnicodeError: ASCII encoding error: ordinal not in range(128)'"some \'\\xcf\' text"'

Thanks for any help.
Nikolai
 
V

vincent wehren

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

In the interpreter:



Traceback (most ....):
UnicodeError: ASCII encoding error: ordinal not in range(128)


"some '\xcf' text"


some '¤' text


'"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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top