I am looking for help accessing key values with special characters (accented letters and such) in Python 3.x dictionary formats. So here's what I am trying to accomplish:
I have a .xml file that I parse into Python with ElementTree:
...
tree = ElementTree.parse(fileNamePath)
...
The source is a program called Cockatrice. It is their card.xml file.
I have a .json text file that I load with json.load(open(fileName)).
The source is: https://mtgjson.com/json/AllCards-x.json.zip
Both databases contain over 16,000 entries and are too cumbersome for me to easily print out at once on the oldPC I must use. Plus, with some of the special characters, CMD isn't always willing to print them.
Anyway...
I am using the names found in the XML file as the variable to use when searching the JSON (converted to DICT) keys.
cardName=root[1][loop_control01].find('name').text
I then pull the info I want from the JSON/DICT with that name and mostly it works well with the exception of when it gets to a name with special characters. An example that keeps popping up is Bösium Strip.
The Error Message is a Key error:
KeyError: 'Bösium Strip'
I have confirmed that the key exists in the JSON by looking through it manually through notepad. In the XML file the text is spelled as:
...
<card>
<name>Bösium Strip</name>...
and in the JSON file it is spelled as:
...
"Bösium Strip":{
"layout":"normal",...
While I do know of the problems printing these characters out in CMD, that does not seem to be the issue here as I am not printing them to screen. I just need to be able to reference the key in searching the JSON/DICT.
I have tried several of the answers found here on StackOverflow to no avail. I either need to search the JSON/DICT using the same format/encoding of characters or I need to iterate through the JSON/DICT and reformat all the keys to a more easily searchable format/encoding.
Any help accomplishing either would make me happy. Thanks to anyone who takes the time to give me a nice solution-present for my birthday today <3