input - How to get file names from command-line parameters in Python -


i've got following code:

with open("test.txt", "r") test, open("table.txt", "w") table:     reader = csv.reader(test, delimiter="\t")     writer = csv.writer(table, delimiter="\t")     row in reader:         if all(field not in keywords field in row):             writer.writerow(row) 

how able convert .py file let define table.txt , test when run it. 1 have write:

script.py test.txt output.txt 

just use sys.argv:

import sys import csv  open(sys.argv[1], "r") test, open(sys.argv[2], "w") table:       # more here 

note, sys.argv[0] contains script name (in case, script.py). first argument, should sys.argv[1]; second argument, should sys.argv[2] , on.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -