No macros in Python

Lulu of the Lotus-Eaters mertz at gnosis.cx
Sun Dec 15 19:46:21 EST 2002


Courageous <jkraska at san.rr.com> wrote previously:
|Of course, for all I know, there's a way to grab the stack and get
|the invokers locals already, if you really insist on this. Is there?

  % cat caller.py
  def caller_locals():
      import sys
      try: raise RuntimeError
      except RuntimeError:
          e,b,t = sys.exc_info()
          caller_locals = t.tb_frame.f_back.f_locals
      print caller_locals

  def somefunc():
      foo = 'bar'
      bat = 'baz'
      caller_locals()

  foo = 'global foo'
  bat = 'global bat'
  somefunc()

  % python caller.py
  {'bat': 'baz', 'foo': 'bar'}

Yours, Lulu...

--
 mertz@   _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i
gnosis  _/_/                    Postmodern Enterprises         _/_/  s r
.cx    _/_/  MAKERS OF CHAOS....                              _/_/   i u
      _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/    g s





More information about the Python-list mailing list