python - Join throws startswith error after using os.walk -


just test script loop entire home directory recursively. on test server, join command throws strange error.

  file "print_idv3.py", line 20, in <module> listdirs("/home/jelmer/")   file "print_idv3.py", line 7, in listdirs list_of_files=os.path.join(root,files)  file "/usr/lib/python2.7/posixpath.py", line 66, in join if b.startswith('/'): attributeerror: 'list' object has no attribute 'startswith' 

the code follows. files , root not empty @ all, should work.

def listdirs(dir):     root, subfolders,files in os.walk(dir,topdown=false):             list_of_files=os.path.join(root,files)             print files             print root             return     return  def main():       #mainrunroutine       return  if __name__=="__main__":     listdirs("/home/jelmer/") 

rather joining string array using os.path.join(), should 2 strings in loop or list comprehension:

list_of_files = [os.path.join(root, f) f in files] 

the difference join each path separately rather using whole array, isn't supported os.path.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -