Python loop over files
<p>I've got a folder with ten files in it which i want to loop through.When I just print out the name of the file my code works fine as below</p>

<pre><code>import os
indir = '/home/des/test'
for root, dirs, filenames in os.walk(indir):
    for f in filenames:
        print f
</code></pre>

<p>prints:</p>

<pre><code>1
2
3
4
5
6
7
8
9
10
</code></pre>

<p>But if I try to open the file in the loop I get an IO error</p>

<pre><code>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 &lt;module&gt;
log = open(f,'r')
IOError: [Errno 2] No such file or directory: '1'
&gt;&gt;&gt; 
</code></pre>

<p>Do I need to pass the full path of the file even inside the loop?</p>
