Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > re.compile() doesn't work under Windows?

Reply
Thread Tools

re.compile() doesn't work under Windows?

 
 
jay graves
Guest
Posts: n/a
 
      08-31-2006
ddtl wrote:
> My script uses re.compile() function, and while it rans without errors
> under Linux, when I ran that script under Windows I get the following
> error:


> Traceback (most recent call last):
> File "C:\a\projects\re.py", line 4, in ?
> import re
> File "C:\a\projects\re.py", line 95, in ?
> main()
> File "C:\a\projects\re.py", line 37, in main
> s_exp = re.compile(op['-s'])
> AttributeError: 'module' object has no attribute 'compile'



> What is the problem here? re module is installed and is on the path -
> for example, the following code works and doesn't cause any errors:


The traceback has the answer. It seems your file is named 're.py' so
it is trying to import itself rather the the 're' python module.

I don't know why it ran OK on Linux. Maybe your script is named
differently on Linux or the sys.path order is different between Windows
and Linux.

HTH.
....
jay

 
Reply With Quote
 
 
 
 
Carsten Haese
Guest
Posts: n/a
 
      08-31-2006
On Thu, 2006-08-31 at 17:38, ddtl wrote:
> Hello everybody.
>
> My script uses re.compile() function, and while it rans without errors
> under Linux, when I ran that script under Windows I get the following
> error:
>
> Traceback (most recent call last):
> File "C:\a\projects\re.py", line 4, in ?
> import re
> File "C:\a\projects\re.py", line 95, in ?
> main()
> File "C:\a\projects\re.py", line 37, in main
> s_exp = re.compile(op['-s'])
> AttributeError: 'module' object has no attribute 'compile'
>
> What is the problem here? re module is installed and is on the path -
> for example, the following code works and doesn't cause any errors:
>
> import re
> re.compile('a')
>
> What else could cause such an error?


Your script is called re, so "import re" is making the script import
itself instead of the re module from the library.

-Carsten


 
Reply With Quote
 
 
 
 
Gabriel Genellina
Guest
Posts: n/a
 
      08-31-2006
At Thursday 31/8/2006 18:38, ddtl wrote:

>My script uses re.compile() function, and while it rans without errors
>under Linux, when I ran that script under Windows I get the following
>error:
>
>Traceback (most recent call last):
> File "C:\a\projects\re.py", line 4, in ?
> import re
> File "C:\a\projects\re.py", line 95, in ?
> main()
> File "C:\a\projects\re.py", line 37, in main
> s_exp = re.compile(op['-s'])
>AttributeError: 'module' object has no attribute 'compile'
>
>What is the problem here? re module is installed and is on the path -
>for example, the following code works and doesn't cause any errors:
>
>import re
>re.compile('a')
>
>What else could cause such an error?


Your *own* module is called re.py, right?
Try another name...



Gabriel Genellina
Softlab SRL





__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

 
Reply With Quote
 
John Machin
Guest
Posts: n/a
 
      08-31-2006
ddtl wrote:
> Hello everybody.
>
> My script uses re.compile() function, and while it rans without errors
> under Linux, when I ran that script under Windows I get the following
> error:
>
> Traceback (most recent call last):
> File "C:\a\projects\re.py", line 4, in ?
> import re
> File "C:\a\projects\re.py", line 95, in ?
> main()
> File "C:\a\projects\re.py", line 37, in main
> s_exp = re.compile(op['-s'])
> AttributeError: 'module' object has no attribute 'compile'
>
> What is the problem here? re module is installed and is on the path -
> for example, the following code works and doesn't cause any errors:
>
> import re
> re.compile('a')
>
> What else could cause such an error?


Change the name of your script file from re.py to
not_the_name_of_a_module.py -- you are importing your script, not the
re module. This is shown in the traceback: import re executes the
main() function in your script.

Worked on Linux? Maybe the script wasn't called re.py on Linux.
Alternatively:

(1) In Windows at least, the current directory is placed first on the
Python module search path. I would have expected the same to happen on
*x.

(2) Did you run it using an IDE on Linux? An IDE may fiddle with
sys.path.

Bottom line: however you ran it on Linux: insert
import sys
print "sys.path is", sys.path
at the top of your script and see what it produces. Note: '' (empty
string) means current directory.

Also it's a good idea to make scripts guard against inappropriate code
being executed when the script is imported (whether deliberately or
accidentally). The standard idiom is something like this:

if __name__ == "__main__": # being run as script, not imported
def main():
do_something()

HTH,
John

 
Reply With Quote
 
ddtl
Guest
Posts: n/a
 
      08-31-2006
Hello everybody.

My script uses re.compile() function, and while it rans without errors
under Linux, when I ran that script under Windows I get the following
error:

Traceback (most recent call last):
File "C:\a\projects\re.py", line 4, in ?
import re
File "C:\a\projects\re.py", line 95, in ?
main()
File "C:\a\projects\re.py", line 37, in main
s_exp = re.compile(op['-s'])
AttributeError: 'module' object has no attribute 'compile'

What is the problem here? re module is installed and is on the path -
for example, the following code works and doesn't cause any errors:

import re
re.compile('a')

What else could cause such an error?


ddtl.
 
Reply With Quote
 
ddtl
Guest
Posts: n/a
 
      09-01-2006
Thanks everybody for pointing out the problem.
And indeed, the script was named differently on Linux.

ddtl.
 
Reply With Quote
 
Sibylle Koczian
Guest
Posts: n/a
 
      09-04-2006
ddtl schrieb:
> Thanks everybody for pointing out the problem.
> And indeed, the script was named differently on Linux.
>
> ddtl.


And because I just spent a day searching all the wrong corners: you
remembered to delete or rename the "re.pyc" that the first import
probably left in the same directory you had "re.py" in?

--
Dr. Sibylle Koczian
Universitaetsbibliothek, Abt. Naturwiss.
D-86135 Augsburg
e-mail : http://www.velocityreviews.com/forums/(E-Mail Removed)-Augsburg.DE
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PSE6: Work-around when Help doesn't work under Windows John Navas Digital Photography 3 01-14-2008 10:04 PM
Tomcat 5.5+ On a Mac, Under Eclipse, Under OS X Edward V. Berard Java 4 04-04-2006 05:14 AM
Why does Rpy/R-plot work under PythonWin, but not under commandline/IDLE? Bo Peng Python 1 01-09-2006 07:05 AM
help : my jar file is not running under linux terminal , but it runs under JbuilderX ide bronby Java 1 07-15-2005 07:23 AM
Java application developped under Linux running ridiculously slow under Windows hshdude Java 12 11-04-2004 05:49 PM



Advertisments