March 4th, 2013, 10:05 AM
UTF-8 decode Error
I need to parse a file and write the contents in a dictionary. The problem is that in some files there are spaces which shouldn`t be there. So I have to replace them with underscore to get the code working as it should.
The parsing works just fine now... But if i access the dictionary later, I get "UTF-8 codec can't decode byte..."
temp = '"'.join(it if not i % 2 else it.replace(' ', u'_') for i, it in enumerate(lines.split('"')))
Unfortunately I can't post code here, which would be to much anyway.
Maybe this problem is known and you can help me?
Ah,... I should mention that I'm using
at the beginning of each file of the project
# -*- coding: utf8 -*-
March 4th, 2013, 03:59 PM
posting more code might help someone figure this out.
How do you open the file?
How do you create the dictionary?
Do you shelve the dictionary then access it with a different python version?
How do you access the dictionary?
[/code] are essential for python code and Makefiles!
March 5th, 2013, 01:55 AM
The dictionary is created dynamically whether a specific string is found or not. Its just somthing like
file = open(path)
allLines = file.readlines()
This Dictionary is then accessed from another module from the same project. (this module gets the object where the dictionary is stored as a parameter)
dict[something][anothersomething]['description'] = replacedString