Error

MRAB python at mrabarnett.plus.com
Wed May 26 14:13:05 EDT 2010


William Miner wrote:
> I’m relative new to python and I puzzled by the following strange (to 
> me) behavior. I was taking pieces from two old scripts to build a new 
> one. When I began to debug it I got the following error message:
> 
> Traceback (most recent call last):
>   File 
> "/Users/williamminer/ex2gen/ex2gen-3.0.5/src/ScriptDev/run_ex2gen_scan.py", 
> line 38, in <module>
>     if re.search('varm',line):
> AttributeError: 'function' object has no attribute 'search'
> 
> This had worked in the previous script but not the new one. I noticed 
> that the new script had an additional line at the beginning (line 3)
> 
> #!/usr/bin/env python
> import sys, math, os, shutil, commands, re, mpmath
> from mpmath import *
> 
> When I deleted this line, the script ran. Why did the line
> 
> from mpmath import *
> 
> Trash the search function fro the regular expression module?
> 
> I’m running Python 2.6.2 on  Mac running OS 10.6.3.
> 
When you write:

     from mpmath import *

you're importing all the 'public' names (by which I mean those not
starting with '_') from the mpmath module.

The mpmath module happens to contain a function called 're', so 're'
will now refer to that function instead of the re module.

That's why using "import *" is usually a bad idea.



More information about the Python-list mailing list