How to send a file as an argument when running another file in Python

Nuff Said nuffsaid at phreaker.net
Fri Feb 6 16:05:02 CET 2004


On Thu, 05 Feb 2004 13:39:53 -0800, se7en wrote:

> I have this file x.py and I need to execute it with y.met as an
> argument.  Unsure of syntax etc...
> 
> -Python newbie

Use:

    import sys

    filename = sys.argv[1]
    print filename

Usage:

    python x.py y.met 

(sys.argv is a list where the first entry (i.e. sys.argv[0]) is
the name of your Python script and the other entries are the
command line arguments which you passed to your script.)

HTH / Nuff




More information about the Python-list mailing list