os.path.exists discrepancy

Discussion in 'Python' started by Robert Brewer, Nov 15, 2004.

  1. 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
     
    Robert Brewer, Nov 15, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anand P Paralkar

    Discrepancy in CLB Usage Report

    Anand P Paralkar, Jul 2, 2003, in forum: VHDL
    Replies:
    0
    Views:
    1,054
    Anand P Paralkar
    Jul 2, 2003
  2. Gopal
    Replies:
    4
    Views:
    395
    Dario
    Oct 30, 2003
  3. Totan
    Replies:
    0
    Views:
    1,037
    Totan
    Apr 17, 2006
  4. Ulf Meinhardt
    Replies:
    8
    Views:
    6,237
  5. Alessandro
    Replies:
    5
    Views:
    578
    Alessandro
    Sep 27, 2010
Loading...

Share This Page