[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

problem with re

Posted on 2006-11-08
9
Medium Priority
?
341 Views
Last Modified: 2010-04-16
I have a very small script:

import re

text = open('eq.txt','r').read()
regex = '[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]'
pattern = re.compile(regex)
match = pattern.findall(text)

print ''.join(match)

However, when I try to run it, I get this error:

Traceback (most recent call last):
  File "/Applications/Komodo.app/Contents/SharedSupport/dbgp/bin/pydbgp", line 66, in <module>
    import dbgp.client
  File "/Applications/Komodo.app/Contents/SharedSupport/dbgp/pythonlib/dbgp/client.py", line 44, in <module>
    import traceback, re
  File "/Users/brian/Desktop/pyFun/re.py", line 5, in <module>
    pattern = re.compile(regex)
AttributeError: 'module' object has no attribute 'compile'

I am guessing here, but it looks like re is not being imported properly.  Although I am sure that there is some really stupid coding error here that I can not see.

Thanks,
Brian
0
Comment
Question by:bnblazer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 11

Expert Comment

by:cjjclifford
ID: 17899620
>>File "/Users/brian/Desktop/pyFun/re.py", line 5, in <module>

Don't call the file "re.py" - its importing itself, not the correct "re" module...
0
 
LVL 1

Author Comment

by:bnblazer
ID: 17899696
Changed the file name - didn't work.  I even re-wrote the file just in case.  I do now have a slightly different error:

Traceback (most recent call last):
  File "/Applications/Komodo.app/Contents/SharedSupport/dbgp/bin/pydbgp", line 66, in <module>
    import dbgp.client
  File "/Applications/Komodo.app/Contents/SharedSupport/dbgp/pythonlib/dbgp/client.py", line 44, in <module>
    import traceback, re
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/re.py", line 5, in <module>
    #
AttributeError: 'module' object has no attribute 'compile'

Here is the error outside of Komodo:

Traceback (most recent call last):
  File "reg.py", line 1, in <module>
    import re
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/re.py", line 5, in <module>
    #
AttributeError: 'module' object has no attribute 'compile'

Brian
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 17899776
I tried your code straight on commandline, and it seems to work fine for me, but I've not got access to Python 2.5 at the moment (using the native Python 2.3.5 on OS-X)

I had a look at the 2.5 doc and it looks the same as expected...
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:bnblazer
ID: 17899833
While I was waiting for a response, I tried some of that too.  I wonder if this is a 2.5 issue?

Brian
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 17899885
Nope, I just installed 2.5 here, and the original code seems to work fine...

Check /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/re.py to make sure it looks OK, especially around the top lines (line 5?) - did it get truncated, or something I wonder...
0
 
LVL 1

Author Comment

by:bnblazer
ID: 17900045
This is really strange - line 5 is a blank comment line with just s #

I just ran this on my SUSE 10.x box with 2.5 installed and it ran fine.

This is getting weird.

Brian
0
 
LVL 17

Accepted Solution

by:
ramrom earned 2000 total points
ID: 17900593
On my Windows system (where I have NOT written my own re.py) I see:
>>> import re
>>> re.__file__
'H:\\Python24\\lib\\re.pyc'

I'll bet when you do this (before erasing anything) the file imported will be from your working directory. Why?

When you ran your re.py, Python created re.pyc in your working directory. import re is loading this file, regardless of what you do with the .py files.

You should see re.pyc in your working directory and another in the .../lib/. Delete the one in your working directory, then try the import again.

0
 
LVL 1

Author Comment

by:bnblazer
ID: 17901076
Ding -

We have a winner.  Thanks ramrom.

Brian
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 17904938
ha, yes, forgot the .pyc - still, related to my original answer...
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The really strange introduction Once upon a time there were individuals who intentionally put the grass seeds to the soil with anticipation of solving their nutrition problems. Or they maybe only played with seeds and noticed what happened... Som…
"The time has come," the Walrus said, "To talk of many things: Of sets--and lists--and dictionaries-- Of variable kinks-- And why you see it changing not-- And why so strange are strings." This part describes how variables and references (see …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question