10

I am working with Eclipse Kepler(2013) and python 3.3.2 and running a simple import like

import glob
a = glob.glob('*')
print(a)

gives a:

TypeError: 'module' object is not callable

This is not the case if I run the same code in Idle. I know I am missing something.

Any help is appreciated.

4

4 回答 4

15

What worked for me was i changed import glob to from glob import glob at the top of the file.

于 2019-03-15T13:32:07.303 回答
6

Probably in your Eclipse environment there's a module named glob that gets imported before the standard library one.

Try printing the glob.__file__ to check it out.

于 2013-09-06T12:05:13.510 回答
6

In some cases people end up using same file name as built in modules. Don't name your file as "glob.py".

于 2015-08-31T05:59:41.103 回答
4

This is only possible if you've defined a package named glob in the module search path, so instead of loading the built-in module glob python is importing that package.

Something like this in the module search path

glob
├── glob.py
├── glob.pyc
├── __init__.py
└── __init__.pyc

will produce the same error:

>>> import glob
>>> glob.__file__
'/home/monty/py/glob/__init__.pyc'
>>> glob.glob()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable

You need to change the name of this package to something else because it seems to be present on the module search path used by eclipse.

于 2013-09-06T12:05:57.423 回答