os.path weirdness

Jeff Layton jeffrey.b.layton at lmco.com
Thu Jun 19 11:20:14 CEST 2003


Peter Hansen wrote:
> Jeff Layton wrote:
> 
>>#!/usr/bin/python
>>
>>import os.path
>>
>>filep="/home1/laytojb/TEMP/tet.out"
>>print "type: ",type(filep)
>>if os.path.isfile(filep): #{
>>     print "Found tet.out"
>>else:
>>     print "Cannot find tet.out"
>>#}
>>
>>This simple script works correctly and finds the
>>file tet.out.
>>    However, when I do virtually the same thing
>>in a much longer script, it can never find the
>>file, even though it exists. 
> 
> 
> Since, clearly, these functions work in most cases, you'd
> better post the relevant tiny section of the larger
> script along with the name of the file it is looking for
> and see what folks say.

Peter,

    I found the bug. Of course, it was something stupid I did
so the files I was checking with os.path.isfile were never
there :) It's not worth really explaining in too much detail,
but needless to say I didn't see the error for the couple of
hours I was debugging. It took a fresh pot of coffee and some
fresh air before I could see the error.
    Also, thanks for the comments below. I haven't used the
debugger at all yet. I'm an old fashioned kind of coder that
uses lots of "write, printf, print" to debug :) I really do
need to learn the debugger though.

Thanks forthe help!

Jeff





More information about the Python-list mailing list