473,741 Members | 5,161 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 1359

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: 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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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: 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: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
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: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.