By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,354 Members | 1,256 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,354 IT Pros & Developers. It's quick & easy.

os.path.exists discrepancy

P: n/a
I've got a webapp which is behaving oddly. I want to include an image on
the webpage, but only if the physical file exists; if it doesn't, I
don't want an img element to generate an ugly blank box. I know the
physical location of the image(s) in question, and figured I'd use
os.path.exists to see if each file exists. A quick test in the
interpreter yields:


However, when I run the following code in the webapp (served by Apache2
+ mod_python on the same Win2k machine):

if not os.path.exists(path):
scan = u"<!-- scan image not found: %s -->" % repr(path)

....I get the output:

<!-- scan image not found: u'S:/Scans/Projects/2004/TJ/04TJ0267.jpg' -->

As you can see, the two paths are equal. Prompting my reaction: bzuh? My
next thought was to read through the os module source--perhaps the
import of "path" was dependent on context. It is, but os.path.__file__
is the same in both contexts: 'C:\\Python23\\lib\\ntpath.pyc'

Any ideas or workarounds?
Robert Brewer
Amor Ministries
Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.