Skip to content

Instantly share code, notes, and snippets.

@stuartmyles
Created July 22, 2015 20:55
Show Gist options
  • Save stuartmyles/15c73a9b8e17ec5dff9c to your computer and use it in GitHub Desktop.
Save stuartmyles/15c73a9b8e17ec5dff9c to your computer and use it in GitHub Desktop.
import ast
class Greeter:
def __init__(self):
#m = "Hello world!"
assignment = ast.Module(body=[ ast.Assign(targets = [
ast.Name(id = 'm', ctx = ast.Store())],
value = ast.Str(s="Hello world!"))
])
ast.fix_missing_locations(assignment)
co = compile(assignment, "<ast>", "exec")
exec(co)
self.message = m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment