On 05/26/2010 10:48 AM, 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 *
Just a guess, (since I don;t have mpmath on hand), but if mpmath has a
definition for something named re, it would overwrite any previous
definition of re.
So general advice says don't use the "from xxx import *" unless you
really *know* what is in the module, and need *all* of it imported.
Either:
from mpmath import x,y,z,whatever
or
import re
import mpmath
... re.search ...
... mpmath.whatever ...
Gary Herron
Trash the search function fro the regular expression module?
I'm running Python 2.6.2 on Mac running OS 10.6.3.
Thanks!
Buff Miner
--
Enig Associates, Inc.
Suite 500, Bethesda Crescent Bldg.
4600 East West Hwy
Bethesda, Maryland 20814
Tel:(301)680-8600
Fax:(301)680-8100
This message is intended only for the use of the intended
recipient(s), and
it may be privileged and confidential. If you are not the intended
recipient, you are hereby notified that any review, retransmission,
conversion to hard copy, copying, circulation or other use of this message
is strictly prohibited and may be illegal. If you are not the intended
recipient, please notify the sender immediately by return e-mail, and
delete
this message from your system. Thank you.
--
http://mail.python.org/mailman/listinfo/python-list