Pythonで関数呼び出しもとの情報を取得

なぜか最近はpythonをいじってます。Rubyは・・・ちょっとお休み。
個人的なメモ。Pythonで関数呼び出しもとの情報を取得(web.pyのソースから)。

python code
  1. import sys
  2. sys._getframe(1).f_locals
  3.  

ほうほう。

python code
  1. def test_func() :
  2.   print sys._getframe(1).f_locals
  3.  
  4. a = "variable a"
  5. b = "variable b"
  6. c = 1
  7. test_func()
  8.  
  9. #>> {'test_func': <function test_func at 0x40657684>, 'a': 'variable a', 'c': 1, 'b': 'variable b', .....}
  10.  

こんな感じで。

Related posts:

07.27.08/12am

No comments yet

trackback uri
  • ajax-loading
  • ajax-loading
  • ajax-loading

Leave a Comment

You can use these tags: <code>, <i>, <em>, <strong>, <a>

About

Author:yuin(http://inforno.net/)

文学部文化学科卒という生粋の文系趣味プログラマ。

主にRuby、Javascript、PHP、JAVA,Python,C,Scala,Schemeなどを使っています。今はPythonな感じかもしれない。今後作曲活動なども復活するかもしれない。

Pages