473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

os.path.exists discrepancy

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:
os.path.exists(u'S:/Scans/Projects/2004/TJ/04TJ0267.jpg')

True

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
MIS
Amor Ministries
fu******@amor.org
Jul 18 '05 #1
0 1338

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Fernando Rodriguez | last post by:
Hi, How can I check for the xistence of any file that matches a wildcard? For example: ppis-*.iss os.path.exists() doesn't expand the wildcard...
31
by: John Roth | last post by:
I'm adding a thread for comments on Gerrit Holl's pre-pep, which can be found here: http://tinyurl.com/2578q Frankly, I like the idea. It's about time that all of the file and directory stuff...
7
by: Earl Eiland | last post by:
os.path.getsize(Inputdirectory + '\\' + Filename) works, but os.path.getsize(Inputdirectory + '\\' + Filename.split('.') + '.ext') Fails reporting "no such file or directory...
4
by: Beman Dawes | last post by:
The docs for os.path.exists(), isdir(), and the like, do not describe behavior when an I/O error occurs. Testing on Windows XP SP2 with Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32, on a...
4
by: Pierre Quentel | last post by:
os.path.exists(path) returns True if "path" exists But on Windows it also returns True for "path" followed by any number of dots : Python 2.4 (#60, Nov 30 2004, 11:49:19) on win32 Type...
1
by: Matthias Ludwig | last post by:
I'm trying to create a directory on the web server with a vb.net code: .... Dim dirName As String = "w:\filepath\images" If Not Directory.Exists(dirName) Then...
2
by: beaker | last post by:
Hi, This may be slightly OT, but as I'm using VB.NET I'll ask anyway... I'm trying to update my path using the following code to tweak the registry Dim regKey As RegistryKey regKey =...
3
by: klappnase | last post by:
Hi all, yesterday I installed Python-2.5 and python-2.4.4 on my windows2k box. When trying to use os.path.exists() to detect which drives are present on the system I noticed that these behave...
0
by: Steve Holden | last post by:
dudeja.rajat@gmail.com wrote: You could use one of the URL libraries. The os.path module is for dealing with the local filesystem. The absence of any exception from f =...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.