I have a lookup table hard-coded in python at the moment that looks something like:
lookup = {
"\x85": u'...', # ...
"\x91": u"'",
...
}
I would like to move the mapping to an external file to make it easier to manage, but have not been able to find a way to store x-escaped character codes and read them back in. Instead of ‘\x85’, I end up with ‘\x85’.
Any ideas?
If you format the file like so:
Then you can use
ast.literal_eval()to get the lookup table into your program:If you want to employ a custom format, you could just store the hex ASCII codes for the keys (e.g.
85,91etc), and convert them while reading: