Python 2.7: I'm trying to use Unicode characters in a simple program via Python's Unicode escape sequences, e.g. typing the string to get a little flower symbol. Sometimes it works, but sometimes when I run the script, it just comes back as the literal . I've assigned unicode strings to several variables which have then been embedded in lists and dictionaries, which could be the source of the problem. When does IDLE translate these strings, and when does it print them as-is?
It seems like IDLE should display the same character every time if your code is giving it the same character every time http://dpaste.com/795389/ have you seen this? http://docs.python.org/howto/unicode.html post you code or a simplified version of it
Thanks for the links, bwCA. I've done some more experimenting... it seems like once you put a unicode string into a tuple or a list or any kind of data structure thing, IDLE stops translating it and just spits it out raw. There was one curious exception; the unicode for 'c', assigned to a variable and then put into a list, came back as <u"c"> when the list was printed, rather than <u"\u0063">. Maybe because it's such a basic character? I'm wondering if there are any workarounds that will let me use unicode strings inside of dictionaries, lists, etc. I'm going to keep looking into it!
Yes... it seems to work if and only if the sequence is not bound inside a larger data structure. Annoying, but I can work with it. Thanks for the help.
a data structure larger than a dictionary? you mean lists within lists within tuples within tuples ......??? if you get down to and access the final item, it should act the same way can you post an example of what you are having a problem with? I am curious
The problem is this: http://dpaste.com/797529/ That goes for any other type of data structure, not just tuples. It's not really an issue anymore, now that I know the sequences will be converted properly if I take them out of the list, dictionary, etc.
Join our real-time social learning platform and learn together with your friends!