Skip to content

Instantly share code, notes, and snippets.

@patwooky
Last active October 21, 2016 05:04
Show Gist options
  • Select an option

  • Save patwooky/dd5c62c88524479004a0989d3ed58528 to your computer and use it in GitHub Desktop.

Select an option

Save patwooky/dd5c62c88524479004a0989d3ed58528 to your computer and use it in GitHub Desktop.
Exiting by sys.exit() in a Module
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')
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