Don't understand error message

Alex cut_me_out at hotmail.com
Tue Apr 25 13:28:13 EDT 2000


> It goes like this:
> 
> import sys, glob, operator
> print sys.argv[1:]
> sys.argv = reduce(operator.add, map(glob.glob, sys.argv))
> print sys.argv[1:]
> 
> When called with "python glob.py *.py" on Win98 I'm supposed to get a list
> of all .py files in the current directory but instead I get:
> 
> Traceback (innermost last):
>   File "glob.py", line 1, in ?
>     import sys, glob, operator
>   File "glob.py", line 3, in ?
>     list = reduce(operator.add, map(glob.glob, '*.py'))
> TypeError: call of non-function (type module)
> 
> Anyone know why?

Yeah, the problem is, your file is called glob.py, and that is loaded
when you import glob.  Instead, you should be loading the glob from the
standard python library.  To get around this, one thing you could do is
rename your glob.py file to my_glob.py, and remove your old glob.py and
glob.pyc.  Then 'python my_glob.py *.py' should work fine.  At least,
that solved the problem for me.

Alex.



More information about the Python-list mailing list