[python-win32] Exceptions occuring when passing parameters.

trader trader at terray.com
Fri Jul 23 05:23:49 CEST 2004


Hi Jody,

This code works for me, and answers your Question #2:

#---------------------------------------------------------------------#
try:
        int('Error') # create an obvious error
except:
        import traceback
        writefile = open('errors.log', 'a')
        traceback.print_exc(file=writefile) # this command outputs the 
                                            # error message as it appears 
                                            # in the interactive 
                                            # environment
        writefile.close()
#---------------------------------------------------------------------#

As an alternative, you could change 'file=writefile' to 'file=sys.stdout',
after importing the sys module, in order to see the code appear in your
DOS window.

You're probably doing something different when passing in your command
line arguments that's hosing up the code.  Any spaces in your path will
break up sys.argv into different pieces.  You'd have to pull it all
together, with code like:

import sys

if len(sys.argv) > 1:
        path2use = " ".join(sys.argv[1:])

It *never* hurts to import the os module and do an os.path.normpath() and
an os.path.exists() on your path argument to verify that your target path 
or direction actually exists.

Hope that helps, and good luck!

JT

P.S.  Your use of r'Y://mymaindir//mysubdir//my_subdir-002' is a little 
screwy.  The r(aw) modifier is meant to turn backslashes (\) into 
literals and not escape characters, which means you can create a path 
string like r'c:\Program Files\MyGreatApp' without having to worry 
about those backslashes having a 'meta' meaning.  Otherwise, you'd have 
to double up on them:  'c:\\Program Files\\MyGreatApp' .  Doubling up 
forward slashes is unnecessary in your example.



More information about the Python-win32 mailing list