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
  • 70,124
  • 20
  • 133
  • 171

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
  • 13,493
  • 3
  • 24
  • 40