I have a string which is automatically converted to byte code by my IDE (very old Boa Constructor). Now I want to convert it to unicode in order to print it with the encoding on the specific machine (cp1252 on windows or utf-8 on Linux).
I use two different ways. One of them is working the other one is not working. But why?
Here the working version:
#!/usr/bin/python
# vim: set fileencoding=cp1252 :
str = '\x80'
str = str.decode('cp1252') # to unicode
str = str.encode('cp1252') # to str
print str
Here the not working version:
#!/usr/bin/python
# vim: set fileencoding=cp1252 :
str = u'\x80'
#str = str.decode('cp1252') # to unicode
str = str.encode('cp1252') # to str
print str
In version 1 I convert the str to unicode via the decode function. In version 2 I convert the str to unicode via the u in front of the string. But I thought, the two versions would do exactly the same?