Kir Kir - 3 months ago 11
Python Question

Pyyhon regular expression works on OSx but not on Windows

expression = re.compile(ur'\?(.*)')


The expression is simple and this project was originally built on a mac. It runs fine on the mac, however it doesn't run on windows failing with

File "path/to/scrapy/spiders/spider.py", line 42
expression = re.compile(ur'\?(.*)')
^

Answer

It is not about Mac vs Windows, I suspect, it is about the Python version you are using to run this code on.

When I run this code on Python 2.7 - it runs fine, no problems. On Python 3.5 I get a SyntaxError (cause of the u prefix, of course):

  File "/Users/user/SO/test.py", line 3
    expression = re.compile(ur'\?(.*)')
                                     ^
SyntaxError: invalid syntax

Check that you are actually using Python 2 on both machines.