[python-win32] Exceptions occuring when passing parameters.

Tim Golden tim.golden at viacom-outdoor.co.uk
Fri Jul 23 10:16:31 CEST 2004


| Hi;
| 	I am new to python and am writting a program that 
| accepts directory paths
| as parameters.
| I am sending r'Y://mymaindir//mysubdir//my_subdir-002' as one of the
| parameters. 

Just to clarify something here, you're going slightly into
overkill mode with that path name. You've obviously avoided
the usual mistake of just passing "c:\path\to\file" where the
"\t" in the middle would be interpreted as a tab, but instead
of just using the r-prefix or just doubling the backslashes or
just using forward-slashes, you've done all three! I'm honestly
rather surprised it even works.

Just to explain, you could do one of these (but I suggest only one):

a) r"y:\mymaindir\mysubdir\mysubdir-002"
b) "y:\\mymaindir\\mysubdir\\mysubdir-002"
c) "y:/mymaindir/mysubdir/mysubdir-002"

To test them out, just try running them at the interactive prompt:

import os
os.listdir (<one of the strings above>)

Now the difference between this and the command-line is that
python will convert whatever you type at the command line
into a python string, so there's no need to put double-quotes
or prefix with an r. 

<myscript.py>
import os, sys

dirname = sys.argv[1]
print dirname
print os.listdir (dirname)
</myscript>

c:\> myscript.py y:\mymaindir\mysubdir\mysubdir-002

You should see the name of the directory
followed by a list of its contents.

Someone else has already given advice on trapping
the error message (basically, run the thing from
the command prompt rather than by double-clicking
on its icon).

I hope that all helps.

TJG


________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


More information about the Python-win32 mailing list