python - Writing general script using open('file', 'r') -
i writing script first read file using with open('file', 'r') file, operation, , write new file using with open('newfile', 'w') newfile.
my question is, need change in script make general number of files, can call script file name terminal python3 script.py file.ext? also, there way write output original file using method?
one way of doing is:
import sys file=open(sys.argv[1], "r") newfile=open("example.txt", "w") content=file.read() #do stuff content here such content=content.upper() newfile.write(content) if inputted command line:
python script.py aaaaaa.txt then file set output have edited content of aaaaaa.txt
hope helps :)
Comments
Post a Comment