そのモジュール内に動的に作成されたクラスを持つpythonモジュールを動的に作成しています。ただし、Python でヘルプ機能を使用すると、クラスが表示されません。問題の例を次に示します。
import imp
Foo = imp.new_module("Foo")
Foo.Bar = type('Bar', (object,), dict(x=10, y=20))
help(Foo)
これは次のことを示しています。
Help on module Foo:
NAME
Foo
FILE
(built-in)
CLASSESセクションに Bar を表示してほしいです。それ、どうやったら出来るの?
help(Foo.Bar)
クラスを として記述していることに注意してくださいin module __main__
。それは手がかりですか?
Help on class Bar in module __main__:
class Bar(__builtin__.object)
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| x = 10
|
| y = 20