Prev: read from bin file
Next: Anybody use web2py?
From: Terry Reedy on 18 Dec 2009 16:56 On 12/18/2009 10:46 AM, Jim Valenza 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. In Python, a 'parameter' is a function local name defined in the header of the function and bound to an argument when the function is called. 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 OUTPUT = '../log/ > SET LOG=..\log > SET COMPLETED=..\Loaded > SET FAILED=..\Errors > SET REPORT=..\log\batch_projectdb.txt > SET SOURCE=..\InBox > SET BACKUP=..\Backup > SET SERVER=housdep01 > SET INSTANCE=port:5151 > SET DATASET=sde > SET /a LOADED=0 > SET /a POSTED=0 > :: If the directories don't exist, later commands run into problems. > > MD %OUTPUT% MD = make directory. Look for this in the os or os.path modules. Do read the tutorial. Terry Jan Reedy > MD %LOG% > MD %COMPLETED% > MD %FAILED% > MD %BACKUP% > I've been researching Parameters with the Python manuals and have not > found the help to be usefull as there is not much documentation for some > reason. I am new to the Python world so maybe I'm missing an important > piece of vocab. > Thanks A lot > Jim >
From: David Robinow on 18 Dec 2009 17:24 On Fri, Dec 18, 2009 at 10:46 AM, Jim Valenza <jim.valenza(a)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
|
Pages: 1 Prev: read from bin file Next: Anybody use web2py? |