473,602 Members | 2,808 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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')


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
fu******@amor.o rg
Jul 18 '05 #1
0 1351

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

Similar topics

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...
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 in the os module got objectified properly (or at least with some semblance of OO propriety!) In the issues section:
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 InputDirectory\\Filename.ext". os.path.getsize(Inputdirectory + r'\' + Filename.split('.') + '.ext') generates a syntax error. Earl Eiland
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 machine with no a: drive, c: is a hard disk with a top level directory named "path" but without a top level directory named "foo", and d: is a CD drive (with no disc inserted): >>> import os >>> print os.path.exists("c:\\")
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 "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.path.exists('Lib/os.py') True # expected
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 Directory.CreateDirectory(dirName) Label1.Text = "Directory created" Else
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 = Registry.CurrentUser.OpenSubKey("Environment", True) Dim s As String = CType(regKey.GetValue("Path"), String)
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 differently: Python 2.4.4 (#71, Oct 18 2006, 08:34:43) on win32 Type "copyright", "credits" or "license()" for more information.
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 = urllib.urlopen("http://www.google.com/webhp/") is a good indication that the addressed page "exists" (but remember that the web is a virtual address space, so it doesn't necessarily mean that
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.