[python-win32] Exceptions occuring when passing parameters.

Jody Burgess jody.burgess at sewardconsulting.com
Thu Jul 22 18:42:32 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. In interactive mode, when executing:

import sys
import os
maindir = r'Y://mymaindir//mysubdir//my_subdir-002'
fileNameList = os.listdir(maindir)
print fileNameList

I get results in the fileNameList list.

However, when executing the same code after passing the path as a parameter
to a python program, I get an error and am unable to see what the error
message. As you can see I am trying to capture the error into a log file.
When this code executes, the os.listdir function fails, and error is
generated and is displayed in the window. I need to be able to trap the
exact error message.

try:
    myfile.write('just before listdir function. Maindir = ' + maindir +
'\n')
    fileNameList = os.listdir(maindir)
except:
    myfile.write(sys.exc_info)
    myfile.write(sys.exc_type)
    myfile.write(sys.exc_value)
    myfile.write('error occurs')

Two questions arise:
	1) Why does the call work in interactive mode and not when parameters are
passed to a program?
	2) How can I trap the exact traceback message that appears on the screen?

Jody Burgess ISP
Systems Analyst
Seward Consulting Ltd.
780.702.5103
jody.burgess at sewardconsulting.com




More information about the Python-win32 mailing list