newbie question...

Tim Chase python.list at tim.thechases.com
Fri Dec 12 12:58:32 EST 2008


> Im new at python and I just want to know if (and how) it is possible
> to send parameters to a program.
> 
> what I mean is that when we start python I can call a file that should
> be run like this: python myfile.py
> can I send additional parameters along with it?  like::: python
> myfile.py myVar1 myVar2

You're looking for sys.argv:

  tim at rubbish:~$ python - one two
  Python 2.5.2 (r252:60911, May 28 2008, 08:35:32)
[GCC 4.2.4 (Debian 4.2.4-1)] on linux2
Type "help", "copyright", "credits" or "license" for more 
information.
  >>> import sys
  >>> sys.argv
  ['-', 'one', 'two']


-tkc






More information about the Python-list mailing list