473,915 Members | 4,448 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

module confusion

Sorry if this is a completely newbie question ...

I was trying to get information about the logging.handler s module, so
I imported logging, and tried dir(logging.han dlers), 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!

Oct 2 '07 #1
40 3527
On Oct 1, 10:03?pm, rjcarr <rjc...@gmail.c omwrote:
Sorry if this is a completely newbie question ...

I was trying to get information about the logging.handler s module, so
I imported logging, and tried dir(logging.han dlers), 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', 'BufferingForma tter', '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',
'_defaultFormat ter', '_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',
'raiseException s', '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!

Oct 2 '07 #2
me********@aol. com wrote:
On Oct 1, 10:03?pm, rjcarr <rjc...@gmail.c omwrote:
>Sorry if this is a completely newbie question ...

I was trying to get information about the logging.handler s module, so
I imported logging, and tried dir(logging.han dlers), 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:
No, he didn't. There is a logging.handler s module; it's just not imported by
importing logging.

OP: logging is a package and logging.handler s 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

Oct 2 '07 #3
In message <ma************ *************** ***********@pyt hon.org>, 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 is a particularly weird case because it is just an alias to the
platform-specific path-handling module; os is not a package.
os is a module, os.path is a variable within that module. That's all there
is to it.
Oct 2 '07 #4
On Tue, 02 Oct 2007 19:34:29 +1300, Lawrence D'Oliveiro wrote:
In message <ma************ *************** ***********@pyt hon.org>, 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.
Oh come on, this is unnecessary nitpicking. Importing the module
`__init__` from a package using the name of the package is close enough to
justify the phrase "I import the package" IMHO.

Ciao,
Marc 'BlackJack' Rintsch
Oct 2 '07 #5
Lawrence D'Oliveiro wrote:
In message <ma************ *************** ***********@pyt hon.org>, 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 is a particularly weird case because it is just an alias to the
platform-specific path-handling module; os is not a package.

os is a module, os.path is a variable within that module. That's all there
is to it.
Yes, but os.path is also module. That's why I said it was a weird case.

In [1]: import os

In [2]: type(os.path)
Out[2]: <type 'module'>

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

Oct 2 '07 #6
In message <ma************ *************** ***********@pyt hon.org>, Robert
Kern wrote:
Lawrence D'Oliveiro wrote:
>In message <ma************ *************** ***********@pyt hon.org>, 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 is a particularly weird case because it is just an alias to the
platform-specific path-handling module; os is not a package.

os is a module, os.path is a variable within that module. That's all
there is to it.

Yes, but os.path is also module. That's why I said it was a weird case.
You can't have modules within modules. os.path isn't an exception--see
below.
In [1]: import os

In [2]: type(os.path)
Out[2]: <type 'module'>
On my Gentoo system:
>>import os
os.path
<module 'posixpath' from '/usr/lib64/python2.5/posixpath.pyc'>

It's just a variable that happens to point to the posixpath module.
Oct 3 '07 #7
In message <ma************ *************** ***********@pyt hon.org>, Steve
Holden wrote:
You *can* import a package ...
You're right. I was misremembering the behaviour of PyCrypto, where
importing the upper-level packages do little more than give you a list of
what algorithms are available.
Oct 3 '07 #8
Lawrence D'Oliveiro <ld*@geek-central.gen.new _zealandwrites:
On my Gentoo system:
>>import os
>>os.path
<module 'posixpath' from '/usr/lib64/python2.5/posixpath.pyc'>

It's just a variable that happens to point to the posixpath module.
There's no "pointing" going on. It's another name bound to the same
object, of equal status to the 'posixpath' name.

Python doesn't have pointers, and even "variable" is a misleading term
in Python. Best to stick to "name" and "bound to".

--
\ "Crime is contagious ... if the government becomes a |
`\ lawbreaker, it breeds contempt for the law." -- Justice Louis |
_o__) Brandeis |
Ben Finney
Oct 3 '07 #9
Lawrence D'Oliveiro a écrit :
In message <ma************ *************** ***********@pyt hon.org>, Robert
Kern wrote:
>Lawrence D'Oliveiro wrote:
>>In message <ma************ *************** ***********@pyt hon.org>, 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 is a particularly weird case because it is just an alias to the
platform-specific path-handling module; os is not a package.
os is a module, os.path is a variable within that module. That's all
there is to it.
Yes, but os.path is also module. That's why I said it was a weird case.

You can't have modules within modules.
If you're talking about the filesystem representation (ie : .py files),
you obviously can't have a file within a file, indeed.

When it comes to the internal runtime representation of modules in
Python, then it's totally different - a module is just an object, that
can of course be an attribute of another module object.
>>import os
type(os)
<type 'module'>
>>type(os.pat h)
<type 'module'>
>>>
os.path isn't an exception--see
below.
>In [1]: import os

In [2]: type(os.path)
Out[2]: <type 'module'>

On my Gentoo system:
>>import os
>>os.path
<module 'posixpath' from '/usr/lib64/python2.5/posixpath.pyc'>

It's just a variable that happens to point to the posixpath module.
It's just a name bound to a module object.
Oct 3 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3168
by: Doug Farrell | last post by:
Hi all, I'm trying to do the following from within a code module: import re # text to match text = "Good morning x something /x, how are you today x something else /x"
2
2002
by: James S | last post by:
Hi, Basically I've been fighting with this code for a few days now and can't seem to work around this problem. Included is the output, the program I use to get this error and the source code for my wrapper. This is acually part of the project, libxmlconf on sourceforge. The newest working version isn't there yet, and cvs is lagged by 6 hours or so. So if you think you want to have a try at this I can tgz the source for you. My...
18
3063
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of a single collections type, I should be proposing a new "namespaces" module instead. Some of my reasons: (1) Namespace is feeling less and less like a collection to me. Even though it's still intended as a data-only structure, the use cases...
17
2058
by: Jacob Page | last post by:
I have created what I think may be a useful Python module, but I'd like to share it with the Python community to get feedback, i.e. if it's Pythonic. If it's considered useful by Pythonistas, I'll see about hosting it on Sourceforge or something like that. Is this a good forum for exposing modules to the public, or is there somewhere more-acceptable? Does this newsgroup find attachments acceptable? -- Jacob
9
2873
by: BartlebyScrivener | last post by:
I know this must have been answered a hundred times, but I must be searching on the wrong terminology. Let's say I have a module foo.py that imports os. I make another script called bar.py that imports foo.py and now I want to use, say, os.walk in bar.py. Which is faster or more correct or whatever: Do I import os at the top of bar.py and use foo's functions?
33
56540
by: christophertidy | last post by:
Hi I am new to Python and have recieved this error message when trying to instantiate an object from a class from another file within the same directory and wondered what I have done wrong. I have a Step.py class: class Step(object) def __init__(self, sName): "Initialise a new Step instance"
4
1670
by: Peter J. Bismuti | last post by:
I'm having trouble understanding how namespaces work in modules. I want to execute a module within the interpreter and then have values that are calculated persist so that other modules that get executed can retrieve them. For example, consider the two simple modules below. The first method fails and I'm not sure exactly why. (Note: assume one instance of an interpreter. In my case a 3rd party software tool that starts an interpreter...
3
1471
by: Jugdish | last post by:
Why doesn't the following work? $HOME/pkg/__init__.py $HOME/pkg/subpkg/__init__.py $HOME/pkg/subpkg/a.py $HOME/pkg/subpkg/b.py # empty import a
2
1847
by: Joe Strout | last post by:
Some corrections, to highlight the depth of my confusion... On Nov 11, 2008, at 9:10 PM, Joe Strout wrote: Actually, it does not. And no, it isn't; it's the NAME of the module the function is in. I'm not sure what good that does me. docstring.testmod does take an
0
10039
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10923
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11066
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7256
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5943
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4778
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3368
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.