模块混乱 [英] module confusion
问题描述
对不起,如果这是一个全新的问题...
我试图获取有关logging.handlers模块的信息,所以
我导入了记录,并尝试了dir(logging.handlers),但得到了:
AttributeError:''module''对象没有属性''处理程序''
我在模块中唯一的经验是os和os.path ...如果我做了同样的事情,只需导入os然后输入dir(os.path),它
按预期显示内容。
所以我的问题是......为什么它们不同?我的意思是,就设计这些模块而言,你将如何在你的名字空间中获得一个子模块
?而另一方面,你怎么去
把它拿出来?
谢谢!
Sorry if this is a completely newbie question ...
I was trying to get information about the logging.handlers module, so
I imported logging, and tried dir(logging.handlers), but got:
AttributeError: ''module'' object has no attribute ''handlers''
The only experience I have in modules is os and os.path ... if I do
the same thing, simply import os and then type dir(os.path), it
displays the contents as expected.
So my question is ... why are they different? I mean, in terms of
designing these modules, how would you go about getting a sub-module
in your name space? And on the other side, how would you go about
getting it out?
Thanks!
推荐答案
10月1日,10:03?pm,rjcarr< rjc ... @ gmail.comwrote:
On Oct 1, 10:03?pm, rjcarr <rjc...@gmail.comwrote:
很抱歉,如果这是一个全新的问题...
我试图获取有关logging.handlers模块的信息,所以
我导入了日志记录,并且尝试了dir(logging.handlers),但得到了:
AttributeError:''module''对象没有属性''handlers''
Sorry if this is a completely newbie question ...
I was trying to get information about the logging.handlers module, so
I imported logging, and tried dir(logging.handlers), but got:
AttributeError: ''module'' object has no attribute ''handlers''
假设消息的含义是什么?
What do suppose that message means?
>
我在模块中唯一的经验是os和os。路径...如果我这么做,只需要导入操作系统然后输入dir(os.path),它就会显示内容符合预期。
>
所以我的问题是......他们为什么不同?
>
The only experience I have in modules is os and os.path ... if I do
the same thing, simply import os and then type dir(os.path), it
displays the contents as expected.
So my question is ... why are they different?
因为你拼错了。首先,在日志记录上做一个dir():
Because you misspelled it. First, do a dir() on logging:
>> import logging
dir(日志记录)
>>import logging
dir(logging)
[''BASIC_FORMAT'',''BufferingFormatter'',''CRITICAL'',' '调试'',''错误'',
''致命'',''FileHandler'',''过滤'',''过滤器'',''格式化'',' 'Handler'',
''INFO'',''LogRecord'',''Logger'',''Manager'',''NOTSET'',''PlaceHolder'',
''RootLogger'',''StreamHandler'',''WARN'',''警告'''''__ author__'',
''__ builtin__'' ,'__ date__'',''__ doc__'',''__ file__'',''_ _ 1 _''','/ b $ b''__ path__'',''_ _ status _''''''__ version__'' ,''_acquireLock'',
''_ defaultFormatter'',''_ handlerList'',''_ handlers'',''_ levelNames'',
''_ lock'',''_ loggerClass'' ,'_releaseLock'',''_ srcfile'',''_ startTime'',
''addLevelName'',''atexit'',''basicConfig'',''cStringIO'' ,'编解码器'',
''关键'',''当前帧'',''调试'',''禁用'',''错误'',''例外'' ,
''致命'',''getLevelName'',''getLogger'',''getLoggerClass'',''info'',''log'',
''logProcesses'',''logThreads'',''makeLogRecord'',''os'',
''greeExceptions'',''root'',''setLoggerClass '',''关闭'',''字符串'',
''sys'',''thread'',''threading'',''time'',''traceback '','类型'',''警告'',
''警告'']
您现在可以从此列表中选择任何项目以进一步扩展
与dir(),但请注意处理程序不是其中之一。
[''BASIC_FORMAT'', ''BufferingFormatter'', ''CRITICAL'', ''DEBUG'', ''ERROR'',
''FATAL'', ''FileHandler'', ''Filter'', ''Filterer'', ''Formatter'', ''Handler'',
''INFO'', ''LogRecord'', ''Logger'', ''Manager'', ''NOTSET'', ''PlaceHolder'',
''RootLogger'', ''StreamHandler'', ''WARN'', ''WARNING'', ''__author__'',
''__builtins__'', ''__date__'', ''__doc__'', ''__file__'', ''__name__'',
''__path__'', ''__status__'', ''__version__'', ''_acquireLock'',
''_defaultFormatter'', ''_handlerList'', ''_handlers'', ''_levelNames'',
''_lock'', ''_loggerClass'', ''_releaseLock'', ''_srcfile'', ''_startTime'',
''addLevelName'', ''atexit'', ''basicConfig'', ''cStringIO'', ''codecs'',
''critical'', ''currentframe'', ''debug'', ''disable'', ''error'', ''exception'',
''fatal'', ''getLevelName'', ''getLogger'', ''getLoggerClass'', ''info'', ''log'',
''logProcesses'', ''logThreads'', ''makeLogRecord'', ''os'',
''raiseExceptions'', ''root'', ''setLoggerClass'', ''shutdown'', ''string'',
''sys'', ''thread'', ''threading'', ''time'', ''traceback'', ''types'', ''warn'',
''warning'']
You can now pick any item from this list to further expand
with dir(), but notice "handlers" isn''t one of them.
我的意思是,就设计这些模块的
而言,你将如何获得一个子模块-module
在你的名字空间?而另一方面,你怎么去
把它拿出来?
谢谢!
I mean, in terms of
designing these modules, how would you go about getting a sub-module
in your name space? And on the other side, how would you go about
getting it out?
Thanks!
me **** **** @ aol.com 写道:
10月1日,10:03?pm,rjcarr< rjc ... @ gmail。 comwrote:
On Oct 1, 10:03?pm, rjcarr <rjc...@gmail.comwrote:
>很抱歉,如果这是一个全新的问题...
我试图获取有关logging.handlers的信息模块,所以
我导入了日志,并尝试了dir(logging.handlers),但得到了:
AttributeError:''module''对象没有属性''handlers''
>Sorry if this is a completely newbie question ...
I was trying to get information about the logging.handlers module, so
I imported logging, and tried dir(logging.handlers), but got:
AttributeError: ''module'' object has no attribute ''handlers''
假设消息的含义是什么?
What do suppose that message means?
>我在模块中唯一的经验是os和os。路径...如果我做同样的事情,只需导入操作系统然后键入dir(os.path),它就会按预期显示内容。
所以我的问题是......为什么他们不一样?
>The only experience I have in modules is os and os.path ... if I do
the same thing, simply import os and then type dir(os.path), it
displays the contents as expected.
So my question is ... why are they different?
因为你拼错了。首先,在记录时做一个dir():
Because you misspelled it. First, do a dir() on logging:
不,他没有。有一个logging.handlers模块;它只是没有导入
导入日志记录。
OP:logging是一个包,logging.handlers是包中的一个模块。不是
包中的所有模块都是通过导入顶层包导入的。
os.path是一个特别奇怪的情况因为它只是一个别名
特定于平台的路径处理模块; os不是套餐。
-
Robert Kern
我已经开始相信整个世界都是一个谜,一个无害的谜团,因为我们疯狂地试图解释它,好像它有一个潜在的真相,这是可怕的。
- Umberto Eco
No, he didn''t. There is a logging.handlers module; it''s just not imported by
importing logging.
OP: logging is a package and logging.handlers is one module in the package. Not
all of the modules in a package are imported by importing the top-level package.
os.path is a particularly weird case because it is just an alias to the
platform-specific path-handling module; os is not a package.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
在消息< ma **************** **********************@python.o rg> ;, Robert
Kern写道:
In message <ma**************************************@python.o rg>, Robert
Kern wrote:
并非通过导入
顶级包导入包中的所有模块。
Not all of the modules in a package are imported by importing the
top-level package.
你不能导入包,只能导入模块。
You can''t import packages, only modules.
os.path特别奇怪因为它只是
特定于平台的路径处理模块的别名; os不是一个包。
os.path is a particularly weird case because it is just an alias to the
platform-specific path-handling module; os is not a package.
os是一个模块,os.path是该模块中的一个变量。这就是它的全部
就是它。
os is a module, os.path is a variable within that module. That''s all there
is to it.
这篇关于模块混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!