django 动态调用模块问题~~

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

django 动态调用模块问题~~

1234-2
>>> import wedding
>>> hasattr(wedding.SitesModule,'weddingmo')
False
>>> from wedding.SitesModule import weddingmo
>>> hasattr(wedding.SitesModule,'weddingmo')
True
>>>
为什么会这样? 为什么 要import weddingmo以后 hasattr 就为True了? 后面的这个 weddingmo 是根据条件动态调用的模块
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: django 动态调用模块问题~~

limodou
On Jan 8, 2008 1:45 PM, 1234 <[hidden email]> wrote:
> >>> import wedding
>  >>> hasattr(wedding.SitesModule,'weddingmo')
>  False
>  >>> from wedding.SitesModule import weddingmo
>  >>> hasattr(wedding.SitesModule,'weddingmo')
>  True
>  >>>
> 为什么会这样? 为什么 要import weddingmo以后 hasattr 就为True了? 后面的这个 weddingmo
> 是根据条件动态调用的模块

要看模板的组织方式。导入包模块,并不一定会自动导入包下的子模块,有时需要显示地导入。主要是看包下的__init__.py是否做了特殊的处理,如从子模块中执行:

from subpackage import *

之类的操作。


--
I like python!
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
meide <<wxPython UI module>>: http://code.google.com/p/meide/
My Blog: http://www.donews.net/limodou
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: django 动态调用模块问题~~

1234-2
谢谢 limdou ~~~ 

在08-1-8,limodou <[hidden email]> 写道:
On Jan 8, 2008 1:45 PM, 1234 <[hidden email]> wrote:
> >>> import wedding
>  >>> hasattr(wedding.SitesModule,'weddingmo')
>  False
>  >>> from wedding.SitesModule import weddingmo
>  >>> hasattr(wedding.SitesModule,'weddingmo')
>  True
>  >>>
> 为什么会这样? 为什么 要import weddingmo以后 hasattr 就为True了? 后面的这个 weddingmo
> 是根据条件动态调用的模块

要看模板的组织方式。导入包模块,并不一定会自动导入包下的子模块,有时需要显示地导入。主要是看包下的__init__.py是否做了特殊的处理,如从子模块中执行:

from subpackage import *

之类的操作。


--
I like python!
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
meide <<wxPython UI module>>: http://code.google.com/p/meide/
My Blog: http://www.donews.net/limodou
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese


_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese