How to open files given as command line arguments in python? [closed]
If you will write the following script:
#!/usr/bin/env pythonimport syswith open(sys.argv[1], 'r') as my_file: print(my_file.read())
and run it, it will display the content of the file whose name you pass in the first argument like that:
./my_script.py test.txt
(in the above example this file will be test.txt
).