开发者

appending list error typeerror sequence item o: expecting string, list found

开发者 https://www.devze.com 2023-04-07 14:07 出处:网络
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.

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 filenam开发者_C百科es:
        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 


The list must be a list of strings for it to work:

"/n".join(["123","123","234"]) # works
"/n".join([123, 123, 234]) #error, this is int

You also get an error if it is a list of lists, which is probably the case in yours:

"/n".join([[123, 123, 234],[123, 123, 234]]) # error

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号