Skip to content

Instantly share code, notes, and snippets.

@nemec
Created December 27, 2011 04:18
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 nemec/1522706 to your computer and use it in GitHub Desktop.
Save nemec/1522706 to your computer and use it in GitHub Desktop.
def _as(var, ident):
import inspect
cur_frame = inspect.currentframe()
outer_locals = inspect.getouterframes(cur_frame)[1][0].f_locals
outer_locals[ident] = var
return var
if __name__ == "__main__":
d = ['a', 'b']
if _as(d[0], 'c') is not None:
print c
else:
print "failed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment