09-22-2015, 08:33 PM
(09-22-2015, 11:36 AM)Segolia Wrote:(09-22-2015, 10:49 AM)Shaadaris Wrote: Is anyone here knowledgeable in python 3, specifically when it comes to JSON and unicodes?
I have a little project I'm working on and I've hit a snag. Anyone remember the idea I had for a procedural pseudo-language generator? Well I'm working on it. Only problem is that the way I have it set up, it writes new words to a JSON file and this happens:
{"dog": "\u0251\u00f8"}
The problem here is that it automatically encodes the nonstandard letters I'm using into this format, which means when I go to compare a string to check if the word already exists in the dictionary file, it thinks it doesn't and rerolls the word because "\u0251\u00f8" does not equal "ɑø".
I've tried encoding and then decoding it in a more manipulatable format like utf8 but the resulting unicode object isn't serializable in JSON meaning I can't write it to the file. I've spent ages trying to fix it and nothing is working at all! ARGH!
From what I'm googling (keep in mind I know basically jack all about character encoding) - try giving "ensure_ascii=False" as a parameter to json.dumps()
This stackoverflow answer suggests you can do it yourself with a lambda function (or regular function) as well. A little bit more wisdom here (but the example code seems to be largely a workaround for python 2 - seems that ensure_ascii=False and encode('utf-8') should be sufficient for python 3 assuming everything else is setup and the input itself is not incorrect in some way)
After putting ensure_ascii=False and encoding=("utf-8") in my json.dump and encoding=("utf-8") in my json.load it just spews out a bunch of completely illegible error messages. (Have I mentioned that Python has the worst error messages I've ever seen?)
ARGHHH! Why can't there just be an option to write and read the bloody things as-is into the text file? I know both Python and txt files can parse the characters in their raw visible form! It would help if all the help on the internet on the subject didn't seem to be trying to fix problems that are just different enough than mine that all the code suggested is useless because it just brings up EVEN MORE errors.
Speaking of which, I've already looked through all 3 links you sent me before I asked for help here >.< Bleh.
Everything I try solves one problem and causes another one...
Which now that I think of it is the definition of programming. WHY DO I ENJOY DOING THIS?
Also, Ehks, are staff applications and everything not in the "Nexus General" section supposed to be visible here by anyone even when not logged in?