UnicodeDecodeError:'ascii'编解码器无法解码位置1的字节0xbe

时间:2014-05-19 02:40:40

标签: python encoding utf-8 cmd

我尝试在cmd中运行文件时收到错误。当我在eclipse中运行它时,它可以工作。无法弄清问题在哪里.. 你能给我一个建议吗?

getConnection
__init__
initialize
Traceback (most recent call last):
  File "D:\workspace\AproximateSearchPython2\Search.py", line 60, in <module>
    main()
  File "D:\workspace\AproximateSearchPython2\Search.py", line 57, in main
    search("weight")
  File "D:\workspace\AproximateSearchPython2\Search.py", line 24, in search
    levenshteinResults=SC.findMatchesByLevenshteinDistance(pattern) # Pre vstupy do 12 znakov
  File "D:\workspace\AproximateSearchPython2\SearchClass.py", line 39, in findMatchesByLevenshteinDistance
    levResults=list(automata.find_all_matches(pattern, k, matcher))
  File "D:\workspace\AproximateSearchPython2\automata.py", line 182, in find_all_matches
    next = lookup_func(match)
  File "D:\workspace\AproximateSearchPython2\automata.py", line 203, in __call__
    pos = bisect.bisect_left(self.l, w)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xbe in position 1: ordinal not in range(128)

1 个答案:

答案 0 :(得分:1)

您需要将字符串编码为utf-8,例如:

u'my non ascii str'.encode('utf-8')