I have a folder with ten files that I want to skip. When I print the file name, my code works fine:
import os indir = '/home/des/test' for root, dirs, filenames in os.walk(indir): for f in filenames: print(f)
What prints:
1 2 3 4 5 6 7 8 9 10
But if I try to open the file in a loop, I get an I / O error:
import os indir = '/home/des/test' for root, dirs, filenames in os.walk(indir): for f in filenames: log = open(f, 'r') Traceback (most recent call last): File "/home/des/my_python_progs/loop_over_dir.py", line 6, in <module> log = open(f, 'r') IOError: [Errno 2] No such file or directory: '1' >>>
Do I need to transfer the full file path even inside the loop?
python
balcoder Aug 03 '12 at 18:30 2012-08-03 18:30
source share