Re: Curious issue with simple code

2006-09-19 Thread codefire
George Sakkis wrote: > By the way, an easier way to deal with paths is the path.py module > (http://www.jorendorff.com/articles/python/path/). Your example could > be rewritten simply as: > > from path import path > for html_file in path(start_dir).walkfiles('*.html'): > print 'html file found

Re: Curious issue with simple code

2006-09-19 Thread George Sakkis
codefire wrote: > Ah of course, isfile(f) can only return true if it can find f! :) > > I'm going to investigate those other functions too :) > > Thanks a lot guys! > Tony By the way, an easier way to deal with paths is the path.py module (http://www.jorendorff.com/articles/python/path/). Your ex

Re: Curious issue with simple code

2006-09-19 Thread codefire
Ah of course, isfile(f) can only return true if it can find f! :) I'm going to investigate those other functions too :) Thanks a lot guys! Tony -- http://mail.python.org/mailman/listinfo/python-list

Re: Curious issue with simple code

2006-09-19 Thread Tim Chase
> [code] > import os > > def print_tree(start_dir): > for f in os.listdir(start_dir): > fp = os.path.join(start_dir, f) > print fp > if os.path.isfile(fp): # will return false if use f here! > if os.path.splitext(fp)[1] == '.html': >

Re: Curious issue with simple code

2006-09-19 Thread MonkeeSage
codefire wrote: > As above it all works as expected. However, on the marked line, if I > use f instead of fp then that condition returns false! Surely, > isfile(f) should return true, even if I just give a filename, rather > than the full path? Hi Tony, Actually the file is in a different directo

Re: Curious issue with simple code

2006-09-19 Thread Diez B. Roggisch
codefire wrote: > Hi, > > I have some simple code - which works...kind of..here's the code: > > [code] > import os > > def print_tree(start_dir): > for f in os.listdir(start_dir): > fp = os.path.join(start_dir, f) > print fp > if os.path.isfile(fp): # will return fal

RE: Curious issue with simple code

2006-09-19 Thread Richard Morello
Dear Tony, You're not in that directory (start_dir) when the isfile() function is called. See function os.path.curdir() and os.chdir(). Also, you may be confusing the behavior of os.path.walk(), in which the function called will happen once you have been chdired to the directory it is examining.

Re: Curious issue with simple code

2006-09-19 Thread Fredrik Lundh
codefire wrote: > As above it all works as expected. However, on the marked line, if I > use f instead of fp then that condition returns false! Surely, > isfile(f) should return true, even if I just give a filename, rather > than the full path? try printing both "f" and "fp", and see if you can