追加列表错误类型错误序列项 o:期望字符串,找到列表
这是我的代码。基本上我认为它应该像这样工作 self.list 制作一个有序列表 self.contents 将列表转换为字符串,以便我可以使用 self.plbuffer.set_text(self.contents) 在可滚动窗口中显示 self.list 。然后 os.walk 遍历 top 中定义的目录,而不是 findall 获取我在 self.search 中编写的内容,找到文件名中的模式,然后将其附加到 self.list 中。
class mplay:
def search_entry(self, widget):
self.list = []
self.contents = "/n".join(self.list)
self.plbuffer.set_text(self.contents)
search = self.search.get_text()
top = '/home/bludiescript/tv-shows'
for dirpath, dirnames, filenames in os.walk(top):
for filename in filenames:
if re.findall(filename, search):
self.list.append(os.path.join([dirpath, filename]))
这个错误是什么意思我可以不使用 os.path.join 附加到 self.list 吗
error = file "./mplay1.py" , line 77 in search_entry
self.contents = "/n".join(self.list) line
typeerror sequence item o: expecting string, list found
this is my code. basicily i think it should work like this self.list makes a ordered list self.contents turns a list into a string so i can display self.list in a scrollable window with self.plbuffer.set_text(self.contents). then os.walk traverses the directory defined in top than findall takes what i write in self.search finds the pattern in filenames and then it should be appended to self.list.
class mplay:
def search_entry(self, widget):
self.list = []
self.contents = "/n".join(self.list)
self.plbuffer.set_text(self.contents)
search = self.search.get_text()
top = '/home/bludiescript/tv-shows'
for dirpath, dirnames, filenames in os.walk(top):
for filename in filenames:
if re.findall(filename, search):
self.list.append(os.path.join([dirpath, filename]))
what does this error mean can i not append to self.list using os.path.join
error = file "./mplay1.py" , line 77 in search_entry
self.contents = "/n".join(self.list) line
typeerror sequence item o: expecting string, list found
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该列表必须是字符串列表才能工作:
如果它是列表列表,您也会收到错误,这可能是您的情况:
放入 print self.list 看看它是什么样子。
当你说它在其他地方运行良好时,可能是因为列表的内容不同。
另请注意,加入空列表 [] 将返回空字符串,因此该行实际上不执行任何操作。
The list must be a list of strings for it to work:
You also get an error if it is a list of lists, which is probably the case in yours:
Throw in a print self.list to see what it looks like.
When you say it runs fine elsewhere, probably that is because the content of the list is different.
Also, note that joining an empty list [] will return an empty string, so that line is effectively doing nothing.