0

我试图让我的应用程序运行带有 Unicode 字符的文件,但为此,您必须在它们之前解码。为此,我正在使用 ConfigObj.py。但是当我运行该应用程序时,出现以下错误:

Traceback (most recent call last):
   File "GCW_Player.py", line 757, in <module>
     epMEDIA ()
   File "GCW_Player.py", line 89, in __ init__
     self.keyhandler (event.key)
   File "GCW_Player.py", line 133, in keyhandler
     if key == K_RIGHT: self.k_goto ()
   File "GCW_Player.py", line 211, in k_goto
     self.go_to ()
   File "GCW_Player.py", line 649, in go_to
     self.list.generate (self.sec_ftypes)
   File "/data/epm_core.py", line 114, in generate
     inp = os.listdir (self.path)
TypeError: coercing to Unicode: need string or buffer, tuple found

下面,让app中对应的part文件:

    def generate(self, filetypes):
        self.data = []
        inp = os.listdir(self.path)
        inp.sort()
        for line in inp:
            file = File(os.path.join(self.path, line), filetypes)
            if file.type != None:
                self.data.append(file)

谁能帮我?我不知道在这种情况下该怎么办。我从来没有经历过这种情况。谢谢你。

4

2 回答 2

2

self.path包含多个路径,也许您需要:

def generate(self, filetypes):
    self.data = []

    for folder in self.path:
        inp = os.listdir(folder)
        inp.sort()
        for line in inp:
            file = File(os.path.join(folder, line), filetypes)
            if file.type != None:
                self.data.append(file)
于 2013-08-14T17:55:58.930 回答
0

好的,很长时间我已经解决了这个问题,通过简单的修改。只是我在所有可以具有 unicode 字符的部分中使用 u"" 字符串。使用 encode.utf8().decode.utf8() 比较困难,所以只需在正确的时刻使用 u"" 字符串。

于 2014-09-28T17:46:59.310 回答