469,909 Members | 1,765 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,909 developers. It's quick & easy.

checking for when a file or folder exists, typing problems?

Hi
I have a little program that is importing from os.path import exists, join,
isdir, normpath, isfile
at one point in my program I check if a file exists using
if exists("c:\projects"):

and that works fine.

If I change it to be
if exists(thepath):
where thepath is a commandline argument it does not work fine.

Note that the commandline is c:\projects and when I print thepath to check what
is going on it prints
c:\projects

The only thing I can assume is that there is some sort of typing problem going
on here, but then it should go ahead and give an error then if it's getting
something unexpected obviously.

Any help on what this error is?

Thanks
--
Bryan Rasmussen

Jul 19 '05 #1
2 4078
Hi Bryan,

Here's a potential idea. Try converting the variable to a string by
using the following syntax:
thePath = str(thePathArg)
This will convert the current variable type to a string, which follows
the data type syntax that you have specified at the beginning of your
message.

Hope this helps,

Brian :-)
---
Bryan Rasmussen wrote:
Hi
I have a little program that is importing from os.path import exists, join,
isdir, normpath, isfile
at one point in my program I check if a file exists using
if exists("c:\projects"):

and that works fine.

If I change it to be
if exists(thepath):
where thepath is a commandline argument it does not work fine.

Note that the commandline is c:\projects and when I print thepath to check what
is going on it prints
c:\projects

The only thing I can assume is that there is some sort of typing problem going
on here, but then it should go ahead and give an error then if it's getting
something unexpected obviously.

Any help on what this error is?

Thanks

Jul 19 '05 #2
Bryan Rasmussen wrote:
... at one point in my program I check if a file exists using
if exists("c:\projects"):


You should not be using a backslash in non-raw-string source to
mean anything but "escape the next character." The above should
either be written as:
if exists(r"c:\projects"):
or:
if exists("c:\\projects"):

I suspect you problem has to do with this difference, but perhaps not.
Give exact short code that actually demonstrates the problem.

--Scott David Daniels
Sc***********@Acm.Org
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Rob Meade | last post: by
11 posts views Thread by Daz | last post: by
42 posts views Thread by =?Utf-8?B?UGxheWE=?= | last post: by
8 posts views Thread by Sweetiecakes | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.