sending an argument

Dave Reed dreed at capital.edu
Sat Aug 3 00:34:36 CEST 2002


> From: Teja Sastry <kurugant at denshi.ece.utk.edu>
> 
> Hi,
>  
>      Could anybody please tell me on how to send an argument to the 
> python program when starting the program like we send argument to c++ 
> executable.  How to read the input entered along with the .py executable 
>  (like "server.py 8000")
> 
> Thanks,
> Teja Sastry

Almost the same as C/C++. Here's the template for all my Python
programs. You can then use argv and len(argv) instead of the C/C++
argc.

import sys

def main(argv):
   pass

if (__name__ == '__main__'):
   main(sys.argv)

Dave




More information about the Python-list mailing list