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! 40 3489
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!
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
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.
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
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
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.
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.
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
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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"
|
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...
|
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...
|
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
|
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?
| |
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"
|
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...
|
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
|
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
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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,...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |