Last active
October 21, 2016 05:04
-
-
Save patwooky/dd5c62c88524479004a0989d3ed58528 to your computer and use it in GitHub Desktop.
Exiting by sys.exit() in a Module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| print 'moduleTestSysExit running' | |
| print __name__ | |
| print 'i am quitting' | |
| # quitting in a module to see if it quit the main running function | |
| # (it actually does quit the main function) | |
| sys.exit('i quit') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import sys | |
| print sys.path | |
| cwd = os.getcwd() | |
| if not cwd in sys.path: | |
| sys.path.append(cwd) | |
| else: | |
| print 'already in sys.path:', cwd | |
| # calling a module that will do a sys.exit() | |
| # to see if it quits the main function | |
| # import moduleTestSysExit | |
| print '\n\n', __name__ | |
| # this will never get run if the module does a sys.exit() | |
| if cwd in sys.path: | |
| sys.path.remove(cwd) | |
| print sys.path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment