except Spam as err: p() try: f() except Spam: g() except Eggs: h() except (Vikings+Marmalade) as err: i() try: a() except Spam: b() except Spam2: c() finally: g() try: a() except: b() else: c() try: a() except: b() else: c() finally: d()
def install(mname, m): import sys sys.modules[mname] = m del sys def generate(parent, mname, attrs): m = create(mname, attrs) # if parent isn't in sys.modules, this won't work... install(parent + '.' + mname, m) return m # this is just a set of random examples, really if __name__ == '__main__': m = create('a', {'b': lambda x: x}) import sys sys.modules['a'] = m print m.b(1) import a print a.b(2) def zoink(x): print x generate('__main__', 'bar', {'baz': zoink}) from __main__.bar import baz baz(3)
pass del a print a def f(): return a def g(): yield a try: raise e except E as a: b() except: c() else: d() for a in aa: if c: continue elif d: e() else: break else: g()
from a import b, c greetings = b("Ornib") print(greetings)