Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #58181 > unrolled thread
| Started by | Yaşar Arabacı <yasar11732@gmail.com> |
|---|---|
| First post | 2013-10-31 16:59 +0200 |
| Last post | 2013-10-31 16:59 +0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
tuple __repr__ non-ascii characters Yaşar Arabacı <yasar11732@gmail.com> - 2013-10-31 16:59 +0200
| From | Yaşar Arabacı <yasar11732@gmail.com> |
|---|---|
| Date | 2013-10-31 16:59 +0200 |
| Subject | tuple __repr__ non-ascii characters |
| Message-ID | <mailman.1880.1383231583.18130.python-list@python.org> |
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?
--
http://ysar.net/
Back to top | Article view | comp.lang.python
csiph-web