tuple __repr__ non-ascii characters

Y

Yaþar Arabacý

Hi,

while this:

a = "yaþar"
print a

prints "yaþar"

this:

a = ("yaþar",)
print a

prints ('ya\xfear',)

At first I tried decoding repr(a) with different encodings, but later
I realised there is actually 4 charaters \, x, f and e in return value
of repr.

Therefore, I wrote this:

def byte_replacement(bstring):
return chr(int(bstring[2:],16))

def prettyprint(obj):
text = repr(obj)
while True:
try:
start = text.index("\\x")
text = text[:start] +
byte_replacement(text[start:start+4]) + text[start+4:]
except ValueError:
break
print text

Is there a better way to handle this problem?
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top