Skip to content

Instantly share code, notes, and snippets.

@stuartmyles
Created July 29, 2015 13:43
Show Gist options
  • Save stuartmyles/9f1887f3f7f9c88e0c61 to your computer and use it in GitHub Desktop.
Save stuartmyles/9f1887f3f7f9c88e0c61 to your computer and use it in GitHub Desktop.
# Use ast to generate an abstract syntax tree to assign an empty tuple to a variable named "nothing"
# i.e. equivalent to
# nothing = ()
import ast
emptyness = ast.Module(body=[ ast.Assign(targets = [
ast.Name(id = 'nothing', ctx = ast.Store())],
value = ast.Tuple(elts=[], ctx = ast.Load()))
])
ast.fix_missing_locations(emptyness)
co = compile(emptyness, "<ast>", "exec")
exec(co)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment