0

The script of run.py as below:

a = open('a.csv')
b = open('b.csv')
c = open('c.csv','w')

while True:
   la = a.readline()
   if not la: break
   lb = b.readline()
   la = la.split('\t')
   lb = lb.split('\t')
   la[4] = str(int(la[4])+int(lb[4]))
   la[5] = str(int(la[5])+int(lb[5]))
   c.write('\t'.join(la)); c.write('\n')

Is it possible to convert it to the format as:

python run.py a.csv b.csv c.csv

So that I can change the file names as arguments in Terminal, Thanks a lot.

Stickers
  • 75,527
  • 23
  • 147
  • 186

1 Answers1

1

You can access the arguments passed to your program via sys.argv.

from sys import argv

a = open(argv[1])
b = open(argv[2])
c = open(argv[3],'w')

# Etc.
Zenadix
  • 15,291
  • 4
  • 26
  • 41