module confusion

Robert Kern robert.kern at gmail.com
Fri Oct 5 01:12:33 EDT 2007


Lawrence D'Oliveiro wrote:
> In message <13gasot6r5bnu1a at corp.supernews.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.path)
>     <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




More information about the Python-list mailing list