Skip to content

Instantly share code, notes, and snippets.

@andreyvit
Created July 18, 2009 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreyvit/149509 to your computer and use it in GitHub Desktop.
Save andreyvit/149509 to your computer and use it in GitHub Desktop.
import module
def handle():
...
def main():
try:
module.test()
except:
handle()
if __name__ == '__main__':
main()
def test():
import third
=== /Users/andreyvit/Projects/hellow/python/third.py(2) None::<module>
frame.f_locals.keys() == ['__builtins__', '__doc__', '__file__', '__name__']
frame.f_globals.keys() == ['__builtins__', '__doc__', '__file__', '__name__']
frame.f_globals['__name__'] == None
frame.f_globals['__file__'] == None
['co_argcount', 'co_cellvars', 'co_code', 'co_consts', 'co_filename', 'co_firstlineno', 'co_flags', 'co_freevars', 'co_lnotab', 'co_name', 'co_names', 'co_nlocals', 'co_stacksize', 'co_varnames']
=== /Users/andreyvit/Projects/hellow/python/module.py(3) None::test
frame.f_locals.keys() == []
frame.f_globals.keys() == ['__builtins__', '__doc__', '__file__', '__name__', 'test']
frame.f_globals['__name__'] == module
frame.f_globals['__file__'] == /Users/andreyvit/Projects/hellow/python/module.pyc
['co_argcount', 'co_cellvars', 'co_code', 'co_consts', 'co_filename', 'co_firstlineno', 'co_flags', 'co_freevars', 'co_lnotab', 'co_name', 'co_names', 'co_nlocals', 'co_stacksize', 'co_varnames']
=== /Users/andreyvit/Projects/hellow/python/main.py(69) None::main
frame.f_locals.keys() == []
frame.f_globals.keys() == ['__builtins__', '__doc__', '__file__', '__name__', 'encode_exception_name', 'extract_tb', 'get_class_name', 'get_traceback', 'handle', 'main', 'module', 'os', 'sys']
frame.f_globals['__name__'] == __main__
frame.f_globals['__file__'] == /Users/andreyvit/Projects/hellow/python/main.py
['co_argcount', 'co_cellvars', 'co_code', 'co_consts', 'co_filename', 'co_firstlineno', 'co_flags', 'co_freevars', 'co_lnotab', 'co_name', 'co_names', 'co_nlocals', 'co_stacksize', 'co_varnames']
print 2 / 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment