The reverse of encode('...', 'backslashreplace')

  • Thread starter =?ISO-8859-1?Q?Tor_Erik_S=F8nvisen?=
  • Start date
?

=?ISO-8859-1?Q?Tor_Erik_S=F8nvisen?=

Hi,

How can I transform b so that the assertion holds? I.e., how can I
reverse the backslash-replaced encoding, while retaining the str-type?

Traceback (most recent call last):
File "<pyshell#59>", line 1, in <module>
assert isinstance(b, str) and b == 'æ'
AssertionError

Regards,
tores
 
D

Duncan Booth

Tor Erik Sønvisen said:
How can I transform b so that the assertion holds? I.e., how can I
reverse the backslash-replaced encoding, while retaining the str-type?


Traceback (most recent call last):
File "<pyshell#59>", line 1, in <module>
assert isinstance(b, str) and b == '‘'
AssertionError

The simple answer is that you cannot: the backslashreplace isn't a
reversible operation. e.g. Try:

There is no way after the encoding that you can tell which of the \xe6
sequences needs reversing and which doesn't. Perhaps the following is
what you want:
 

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
474,260
Messages
2,571,039
Members
48,768
Latest member
first4landlord

Latest Threads

Top