#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    UTF-8 decode Error


    Hi,

    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.

    Code:
    temp = '"'.join(it if not i % 2 else it.replace(' ', u'_') for i, it in enumerate(lines.split('"')))
    The parsing works just fine now... But if i access the dictionary later, I get "UTF-8 codec can't decode byte..."
    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

    Code:
    #!/usr/bin/env python 
    # -*- coding: utf8 -*-
    at the beginning of each file of the project
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,996
    Rep Power
    481
    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]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0
    Open file:

    Code:
    file = open(path)         
    allLines = file.readlines()
    The dictionary is created dynamically whether a specific string is found or not. Its just somthing like

    Code:
     dict[something][anothersomething]['description'] = replacedString
    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)

IMN logo majestic logo threadwatch logo seochat tools logo