[英]python modules appearing out of no where
Today one peculiar thing happened to me .I was trying to get a hang of appengine and Django on www.shell.appspot.com when i entered dir(django)
the o/pi got was 今天有一件奇怪的事发生在我身上。当我进入dir(django)
o / pi得到的时候,我试图在www.shell.appspot.com上获得一些appengine和Django。
['VERSION', '__builtins__', '__doc__', '__file__', '__name__', '__path__', 'conf', 'core', 'template', 'utils']
but still i tried 但我还是试过
from django import forms
and it worked to my surprise , while there was no trances of this on the o/p of dir()
.so out of curiosity i again entered dir(django)
and the o/pi got was 而且令我惊讶的是,虽然dir()
的o / p没有恍惚状态。出于好奇,我再次进入dir(django)
并且o / pi得到了
['VERSION', '__builtins__', '__doc__', '__file__', '__name__', '__path__', 'conf', 'core', 'forms', 'oldforms', 'template', 'utils']
note the forms element here .So can any one explain to me where this forms come from ? 请注意这里的表格元素。任何人都可以向我解释这些表格的来源吗?
The statement from package import module
loads (if it had not been previously loaded) package/module.py
(after first loading package/__init__.py
if it hadn't previously loaded it already) and adds 'module'
as an entry in the package (as well as a variable in the current scope). from package import module
的语句加载(如果以前没有加载过) package/module.py
(首先加载package/__init__.py
如果之前没有加载它)并添加'module'
作为条目包(以及当前范围中的变量)。 So dir(package)
will show a 'module'
entry after the import, but not before. 因此dir(package)
将在导入后显示'module'
条目,但不会在之前显示。
A package can contain unbounded numbers of modules and subpackages (recursively) so it would be very slow to load everything in the package (just to fill out its dir
!-) until specific modules and subpackages are specifically imported -- so, the loading of the latter is "just in time", when they're imported for the first time (and only then do they show up in the paren package's dir
). 一个包可以包含无限数量的模块和子包(递归),因此加载包中的所有内容(只是为了填写它的dir
! - )直到特定的模块和子包被专门导入 - 所以,加载后者是“及时”,当他们第一次进口时(只有那时它们出现在paren包的dir
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.