module confusion

mensanator at aol.com mensanator at aol.com
Tue Oct 2 06:41:48 CEST 2007


On Oct 1, 10:03?pm, rjcarr <rjc... at gmail.com> wrote:
> 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?

>
> 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?  

Because you misspelled it. First, do a dir() on logging:

>>> import logging
>>> dir(logging)
['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.

> 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!





More information about the Python-list mailing list