Python:getattr: モジュールレベルの関数の解決

こんなんでいいんかな。

(op)hdknr@debuniid:~/.virtualenvs/op/src/djopenid$ vi experiment/server.py

import server as __module__
def test():
    return getattr(__module__,’hoge’)
def hoge():
    print "hogehoge"

(op)hdknr@debuniid:~/.virtualenvs/op/src/djopenid$ !py
python manage.py shell
Python 2.5.4 (r254:67916, Sep 26 2009, 08:19:36)
[GCC 4.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from experiment.server import *
>>> hoge()
hogehoge
>>> test()
<function hoge at 0x996ddbc>
>>> test()()
hogehoge

カテゴリー: 未分類 パーマリンク

コメントを残す