TypeError: 'module' object is not callable (newby question)

John Machin sjmachin at lexicon.net
Mon Aug 14 17:55:11 EDT 2006


Charles Russell wrote:
> Marc 'BlackJack' Rintsch wrote:
>
> >
> > Don't call your file `glob.py` because then you import this module and not
> > the `glob` module from the standard library.
> >
> > Ciao,
> > 	Marc 'BlackJack' Rintsch
>
> Yes, thanks.  Renaming to myglob.py solved the problem. But why does the
> conflict not occur when the code is run interactively from the python
> prompt?

It does for me on Windows -- see below --because '' (representing the
cwd) is injected at the front of sys.path.  *xMMV of course. Or perhaps
when you ran it your cwd was some other directory.

C:\junk>dir glob*
[snip]
15/08/2006  04:28 AM               662 glob.py
15/08/2006  04:28 AM               592 glob.pyc
[snip]
C:\junk>python
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
|>>> import glob
*** Aarrgghh!! I'm being imported as glob
glob was imported from glob.pyc
glob.glob is <type 'module'>
glob.glob was imported from glob.pyc
(glob.glob is glob) is True
--- end of import
|>>>

Cheers,
John




More information about the Python-list mailing list