I have a database which is synchronized against an external web source twice a day. This web source contains a bunch of entries, which have names and some extra information about these names.
Some of these names are silly and I want to rename them when inserting them into my own database. To rename these silly names, I have a standard dictionary as such:
RENAME_TABLE = { "Wσird" : "Weird", ... }
As you can see, this is where UTF-8 comes into play. This is the function which performs renaming of all the problematic entries:
def rename_all_entries():
all_keys = RENAME_TABLE.keys()
entries = Entry.objects.filter(name__in=all_keys)
for entry in entries:
entry.name = RENAME_TABLE[entry.name]
entry.save()
So it tries to find the old name in RENAME_TABLE
and renames the entry if found. However, I get a KeyError
exception when using RENAME_TABLE[entry.name]
.
Now I'm lost, what do I do? I have...
# -*- coding: utf-8 -*-
...in the top of the Python file.