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

jay graves jaywgraves at gmail.com
Thu Aug 31 16:44:44 EDT 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




More information about the Python-list mailing list