Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle invalid arguments #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

egandunning
Copy link

Running Exporter.py with invalid arguments resulted in the following error message:

$ python Exporter.py --whoops
Traceback (most recent call last):
File "Exporter.py", line 79, in <module>
main(sys.argv[1:])
File "Exporter.py", line 75, in main
outputFile.close()
UnboundLocalError: local variable 'outputFile' referenced before assignment

I moved all file io into a with block, and removed the finally block. This way, if getopt() throws an exception, the program won't call close() on an uninitialized variable.

Running the same command now gives the following output:

$ python Exporter.py --whoops
Arguments parser error, try -h

option --whoops not recognized

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant