So my program takes a CSV file that's already made and makes a new file that's more organized. It works fine when I run the program from within a Windows command prompt window. But it prints out the error message that before.csv cannot be found when running it using Win+R. The CSV file is in the same folder as the batch script used to run Python with the Python script file and two CSV file names like before.csv and after.csv.
Does anyone know what could be wrong?
import csv
import sys
def main():
if len(sys.argv) < 3:
sys.exit("Too few command-line arguments")
elif len(sys.argv) > 3:
sys.exit("Too many command-line arguments")
else:
if sys.argv[1][-4:] != ".csv":
sys.exit("Not a CSV file")
else:
clean(sys.argv[1], sys.argv[2])
def clean(input, output):
try:
with open(input) as input:
reader = csv.DictReader(input)
with open(output, "w") as output:
header = ["first", "last", "house"]
writer = csv.DictWriter(output, fieldnames = header)
writer.writeheader()
for student in reader:
last, first = student["name"].split(", ")
house = student["house"]
writer.writerow({"first": first, "last": last, "house": house})
except FileNotFoundError:
sys.exit(f"Could not read {input}")
if __name__ == "__main__":
main()
PS So I'm seeing that I need to add the full PATH name to my arguments. Thing is don't that kind defeat the purpose of Win-r being quick if I have to type all that.