Nov-01-2016, 08:20 PM
You still need to correct the other mistakes, even with a try/except.
The sys.argv is going to return either a one element list or a string. By using sys.argv[1] you will receive an error:
So:
The sys.argv is going to return either a one element list or a string. By using sys.argv[1] you will receive an error:
Error:Traceback (most recent call last):
File "C:/Python/Samples/scratch.py", line 3, in <module>
file_loc = sys.argv[1]
IndexError: list index out of range
Remember in Python, a list starts with '0', not a '1'So:
file_loc = sys.argv[0] print("file_loc = ", file_loc) print("file_loc type = ", type(file_loc))returns:
Output:file_loc = C:/Python/Samples/scratch.py
file_loc type = <class 'str'>
Length of 'arg' is: 28
and:file_loc = sys.argv print("file_loc = ", file_loc) print("file_loc type = ", type(file_loc))returns:
Output:"C:\Python 3.5\python.exe" C:/Python/Samples/scratch.py
file_loc = ['C:/Python/Samples/scratch.py']
file_loc type = <class 'list'>
Length of 'arg' is: 1
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition