sending an argument

Mark McEahern marklists at
Sat Aug 3 00:36:41 CEST 2002

>      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 " 8000")

Short answer:  sys.argv.

Long answer:

#!/usr/bin/env python

if __name__ == "__main__":
  import sys
  import os
  usage = "%s count" % (os.path.basename(sys.argv[0]))
    count = int(sys.argv[1])
    print count ** 2
    print usage

// m

More information about the Python-list mailing list