比方说,我有这样的代码:调用构造函数没有赋值;实例后
models.py:
class Square:
def __init__(self, name, value):
self._name = name
self._value = value
mymodule.py:
from models import Square
Square('hello', 'there')
main.py
m = __import__('mymodule')
for i in dir(m):
if i == 'Square':
models.append(getattr(m, i))
我的问题是:我如何实例化附加的Square I(使用我在mymodule.py中给出的参数)当然)?
想法是稍后实例化Square。
谢谢!
main.py中'models'从哪里来的? – martineau 2013-02-12 22:48:06
@martineau只是一些python列表。 – user1491915 2013-02-12 22:59:00
好的,因为你在mymodule.py中有'from models ...'而且你的main.py中没有定义它, – martineau 2013-02-12 23:29:36