PYTHON get files from command line

前端 未结 8 569
夕颜
夕颜 2020-12-04 18:04

How do you get a file name from command line when you run a Python code? Like if your code opens a file and reads the line, but the file varies whenever you run it, how to y

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-04 18:25

    Just use the basic command raw_input

    declare input file name as string

    inFile = ""
    inFile = raw_input("Enter the input File Name: ")
    

    Now you can open the file by using with open(inFile,'w')

提交回复
热议问题