[Tutor] Using sys.argv[]

Cliff Martin camartin@snet.net
Sun, 01 Jul 2001 22:35:38 -0400


To all:

I have a program that I use regularly.  (I'm using Linux , kernel 2.4.0
with Python 2.0) It's format is from the command line,  Mathprogram
inputfilename outputfilename.  Inputfilename has the detailed
information  that the program operates on. I want to write a script to
do this for me and let me decide the input files to use from the command
line (I intend to make this more complicated later). I wrote a simple
script that used os.system("Mathprogram inputfilename outputfilename").
This worked well. But when I tried to use sys.argv[ ] to set the file
names from the command line it couldn't open the input filename to
read.  The code looks like

#! /usr/bin/python

import os
import sys
os.system("Mathprogram sys.argv[1] sys.argv[2]")


Then from the command line I run

python scrfaim.py inputfilename outputfilename

and I get the error "error opening sys.argv[1] for reading".

So what am I doing wrong. It seems a straightforward enough function
that I must be using sys.argv wrong. By the way my paths etc. seem to be
setup correctly.

Thanks in advance

Cliff