Reputation: 444
I have a field in a sqlite3 db that contains strings like:
title = "Friedrich_N\u00FCrnberg"
I read this strings in a variable and I want to pass the unicode version of it to a subprocess.Popen call.
The software I am calling through Popen needs to receive as input this:
Friedrich_Nürnberg
instead of this:
Friedrich_N\u00FCrnberg
otherwise the its computation is vain.
This is the calling code:
subprocess.Popen([command, title], stdout=subprocess.PIPE)
How can I modify it?
Thanks a lot.
PS. If I manually try adding a u"" it works, but I cannot use that syntax because I am not explicitly stating the text content of each variable.
Upvotes: 2
Views: 4744
Reputation: 6466
That is called a Unicode escape sequence. The desired character you want is called an encoded character.
Here is an example of decoding unicode escape sequences in the Python shell.
>>> title = "Friedrich_N\u00FCrnberg"
>>> character = title.decode("unicode-escape")
>>> character
u'Friedrich_N\xfcrnberg'
>>> print character
Friedrich_Nürnberg
You could try:
title = title.decode("unicode-escape")
subprocess.Popen([command, title], stdout=subprocess.PIPE)
I wrote another answer which I think explains this fairly well. Decoding Unicode in Python
Upvotes: 2