def find_globals(node, globs):
 for n in node:
  if isinstance(n, AST):
   globs = find_globals(n, globs)
  elif (n.type in ('STORE_GLOBAL', 'DELETE_GLOBAL')):
   globs.add(n.pattr)
 return globs

def find_globals ( node , globs ) : for n in node : if isinstance ( n , AST ) : globs = find_globals ( n , globs ) elif ( n . type in ( 'STORE_GLOBAL' , 'DELETE_GLOBAL' ) ) : globs . add ( n . pattr ) return globs
uses ast to find globals in an ast tree .