Setting Parameters inside of code

David Robinow drobinow at gmail.com
Fri Dec 18 17:24:39 EST 2009


On Fri, Dec 18, 2009 at 10:46 AM, Jim Valenza <jim.valenza at gmail.com> wrote:
> Hello All - I have a very novice question for any of you out there.  I need
> to assign several parameters to a code in python. I have an example of a
> code that was in DOS that I would need to set as parameters in my Python
> script.
>
> SetLocal EnableDelayedExpansion
> SET OUTPUT=..\log
> SET LOG=..\log
> SET COMPLETED=..\Loaded

You have an unusual use of the word "parameter". What you are doing is
setting environment variables. You can read these values in Python

import os
outvar = os.getenv("OUTPUT")
logvar = os.getenv("LOG")
completevar = os.getenv("COMPLETED")

# etc
print outvar
print logvar
print completevar

------
You may also want to pass arguments (I think 'argument' is what you
called 'parameter') to your script:
   myScript.py firstArg secondArg thirdArg

hunt for sys.argv in the documentation.
----

For more sophisticated argument passing you may want to look at the
'optparse' module



More information about the Python-list mailing list