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

S

se7en

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

-Python newbie
 
N

Nuff Said

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top