Do I need to pass the full path of a file in another directory to open()?

后端 未结 5 2128
盖世英雄少女心
盖世英雄少女心 2020-12-05 03:58

I have a folder with ten files in it which I want to loop through. When I print out the name of the file my code works fine:

import os
indir = \'/home/des/te         


        
5条回答
  •  生来不讨喜
    2020-12-05 04:31

    Here's a snippet that will walk the file tree for you:

    indir = '/home/des/test'
    for root, dirs, filenames in os.walk(indir):
        for f in filenames:
            print(f)
            log = open(indir + f, 'r')
    

提交回复
热议问题