473,786 Members | 2,368 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
40 3493
"Lawrence D'Oliveiro" <ldo@ge...ew_ze alandwote:
Honestly, why do people react to the word "pointer" as though computers have
to wear underwear to conceal something shameful going on in their nether
regions?
I think it is because a pointer is a variable containing as a value the address
of something.

So its a low level concept - useful to low-lifes like C and assembler
programmers, and as
such, capable of causing extreme mayhem in your nicely structured, high level
life.

So it boils down to fear - also known as: "once bitten, twice shy"

:-) - Hendrik
Oct 4 '07 #21
On Thu, 04 Oct 2007 11:11:03 +1300, Lawrence D'Oliveiro wrote:
In Python, all names _are_ variables. They are not "bound" to objects.
The general convention among Python programmers is to describe names
being bound to values. While the analogy to real life binding of objects,
it's close enough to be useful.

The value of os.path is a pointer. It's implemented as a pointer, it has
all the semantics of a pointer.
Ah, I see you are a devotee of Humpty Dumpty:

"When I use a word," Humpty Dumpty said, in rather
a scornful tone, "it means just what I choose it to
mean-neither more nor less."

"The question is," said Alice, "whether you can
make words mean so many different things."

"The question is," said Humpty Dumpty, "which is to
be master -- that's all."
The rest of the world understands pointers to be in the sense of pointers
in C, Pascal and similar: a low level construct that is to all extents
and purposes a memory location whose content is itself a memory location.

Oh sure, I suppose there are a few pedants who insist that "pointer" just
means "something which points to something else". There may even be a
language or two whose users regularly use the term "pointer" to mean
something other than the common usage, and may never have been exposed to
the common usage.

And thus, satisfied in their own mind that *technically* they're right,
or at least not provably wrong, the pedants insist on calling Python
names "pointers" regardless of the confusion it confuses to the majority
of programmers and despite the violence they have to do to the human
language for it to work.

Of course, we can *easily* find out what the type of os.path is. Python
allows us to interrogate any object and find out its type:
>>import os
type(os.pat h)
<type 'module'>

It's a module, not a pointer. End of story.

Honestly, why do people react to the word "pointer" as though computers
have to wear underwear to conceal something shameful going on in their
nether regions?
The real question is why people insist on hammering the square peg of C
terminology into the round holes of Python's object model.

--
Steven.
Oct 4 '07 #22
In message <13************ *@corp.supernew s.com>, Steven D'Aprano wrote:
... pedants ...
When people use that word against me, it's generally a sign they're trying
not to admit I'm right.
Oct 4 '07 #23
Lawrence D'Oliveiro wrote:
In message <13************ *@corp.supernew s.com>, Steven D'Aprano wrote:
>... pedants ...

When people use that word against me, it's generally a sign they're trying
not to admit I'm right.
If it were less important to be right and more important to be
considerate this thread could end without a further contribution from
you ...

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline so I couldn't cat it

Oct 4 '07 #24
Lawrence D'Oliveiro a écrit :
In message <ma************ *************** ***********@pyt hon.org>, Carsten
Haese wrote:
>On Thu, 2007-10-04 at 11:11 +1300, Lawrence D'Oliveiro wrote:
>>In Python, all names _are_ variables. They are not "bound" to objects.
The value of os.path is a pointer.
No. "os.path" refers to the object that's known as the "path" attribute
of the object known as "os". That object, in turn, is a module.

No, it's a variable. It just happens to contain a pointer to a module.
Lawrence, you should have a look at CPython's source code. And at other
implementations too. Python's "variables" *really* are name/object pairs
- most of the time key/value pairs in a dict. The name itself is just
that : a name. It doesn't "contains" anything, it's *not* a label for a
memory address, it's *only* a name.
>> It's implemented as a pointer,
While it is true that namespaces are implemented in CPython as
collections of pointers to PyObject structures, that's an irrelevant
implementati on detail. I doubt that they are implemented as pointers in
Jython, PyPy, or IronPython.

I'll bet they are.
Since Java doesn't have pointers, you lost your bet.
>> it has all the semantics of a pointer.
No, it doesn't. A pointer means the physical address of a memory
location, which implies that you can overwrite that memory location. Can
you do that in Python?

Yes. Look up the definition of "mutable objects".
I think Carsten knows this definition. But it has nothing to do with
"overwritin g a memory location" - like you could do in C using pointers.

Oct 4 '07 #25
On 2007-10-03, Lawrence D'Oliveiro <ld*@geek-central.gen.new _zealandwrote:
In message <87************ @benfinney.id.a u>, Ben Finney wrote:
>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".

In Python, all names _are_ variables. They are not "bound" to
objects. The value of os.path is a pointer. It's implemented as
a pointer, it has all the semantics of a pointer.
No. A pointer is also an iterator.

void duplicate(char *d, const char *s)
{
while (*d++ = *s++)
;
}

What does that look like implemented with Python names?

def duplicate(d, s):
raise AbstractionViol ationError("Pyt hon identifiers aren't pointers.")

Moreover, it seems difficult to promote the concept of a pointers
in a language which doesn't provide a "take the address of an
object" operation.
Honestly, why do people react to the word "pointer" as though
computers have to wear underwear to conceal something shameful
going on in their nether regions?
Refraining from thinking about pointers (unless I have to) saves
wear and tear on the old bean. I also like to think of 5 as an
integer most of the time.

--
Neil Cerutti
Will the last person to leave please see that the perpetual light is
extinguished --sign at New England church
Oct 4 '07 #26
On Thu, 04 Oct 2007 23:01:06 +1300, Lawrence D'Oliveiro wrote:
In message <13************ *@corp.supernew s.com>, Steven D'Aprano wrote:
>... pedants ...

When people use that word against me, it's generally a sign they're
trying not to admit I'm right.
Yeah, you keep telling yourself that.

What does type(os.path) return when you try it?

--
Steven.
Oct 4 '07 #27
In message <13************ *@corp.supernew s.com>, Steven D'Aprano wrote:
What does type(os.path) return when you try it?
It returns the type of the value contained in that variable, of course:
>>import os
os.path = 3
type(os.pat h)
<type 'int'>

See, it's just a variable, like any other.
Oct 4 '07 #28
In message <sl************ ********@FIAD06 .norwich.edu>, Neil Cerutti wrote:
On 2007-10-03, Lawrence D'Oliveiro <ld*@geek-central.gen.new _zealand>
wrote:
>In message <87************ @benfinney.id.a u>, Ben Finney wrote:
>>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".

In Python, all names _are_ variables. They are not "bound" to
objects. The value of os.path is a pointer. It's implemented as
a pointer, it has all the semantics of a pointer.

No. A pointer is also an iterator.

void duplicate(char *d, const char *s)
{
while (*d++ = *s++)
;
}
So if you can't do pointer arithmetic, then it's not a pointer? Trying this:

void duplicate(void *d, const void *s)
{
while (*d++ = *s++)
;
}

I get:

test.c: In function 'duplicate':
test.c:3: warning: dereferencing 'void *' pointer
test.c:3: warning: dereferencing 'void *' pointer
test.c:3: error: invalid use of void expression

So you can't do arithmetic or iterate with a void * pointer. Does that mean
it's not really a pointer?
Oct 5 '07 #29
Lawrence D'Oliveiro wrote:
In message <13************ *@corp.supernew s.com>, Steven D'Aprano wrote:
>What does type(os.path) return when you try it?

It returns the type of the value contained in that variable, of course:
>>import os
>>os.path = 3
>>type(os.pat h)
<type 'int'>

See, it's just a variable, like any other.
Oooookay. No one is contending that the "os.path" name can't be reassigned to a
different object or that the "os.path" name is somehow different from any other
name in Python. It's not wrong to say that "os is a module" either, even though
you can obviously reassign that name to another object, too.

What I meant when I said "os.path is a bit of a weird case" is that, by default,
the object referred to by the name "os.path" (assuming you've imported the
standard library's os module) is another module and that os itself is a module,
not a package like logging is. This is somewhat odd, because most modules aren't
exposed that way. They are either in their own file and accessed by importing
them directly, or they are inside 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 5 '07 #30

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

Similar topics

1
3164
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
1994
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
3052
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
2048
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
2867
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
56499
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
1661
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
1462
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
1837
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
9647
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
10357
Oralloy
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...
0
10163
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...
0
9959
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
8988
agi2029
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...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
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
5397
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...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.