Hi Huji,
It does look like the difference in Python versions is the problem. The Python
3 docs <https://docs.python.org/3/reference/lexical_analysis.html> say:
Both string and bytes literals may optionally be prefixed with a letter 'r'
or 'R'; such strings are called *raw strings*
and treat backslashes as
literal characters. As a result, in string literals, '\U' and '\u'
escapes in raw strings are not treated specially. *Given that Python
2.x’s raw unicode literals behave differently than Python 3.x’s the 'ur'
syntax is not supported.*
So the syntax you tried to use is indeed invalid. I don't really know what
the exact difference is between Python 2 and Python 3 raw Unicode literals,
but since in Python 3 literal strings are always taken as Unicode, you can
probably just use *r'...'* for your regular expression and settle on Python
3 for both local development and on Toolforge.
Hope this helps!
2018-08-19 21:57 GMT+01:00 Huji Lee <huji.huji(a)gmail.com>om>:
Excellent question. On my own computer, I am using
2.7.12 but on labs it
is 3.4.3
Of note, when I changed my code such that all cases of *ur'...'* now read
*u'...'
*the script worked in both environments. So it has to do with how
escaping works in python, I guess. But I am not sure.
On Sun, Aug 19, 2018 at 4:48 PM Alex Monk <krenair(a)gmail.com> wrote:
What are the versions of Python involved?
On Sun, 19 Aug 2018 at 21:34, Huji Lee <huji.huji(a)gmail.com> wrote:
Hello,
When I run this script[1] on my own machine it runs without any problem.
When I run it on Labs, I get an invalid syntax error, pasted below. Can you
please help me figure out why?
Thanks!
(venv)tools.huji@tools-bastion-03:~$ python core/pwb.py webcite
-page:"SOME PAGE"
Traceback (most recent call last):
File "core/pwb.py", line 253, in <module>
if not main():
File "core/pwb.py", line 246, in main
run_python_file(filename, [filename] + args, argvu, file_package)
File "core/pwb.py", line 114, in run_python_file
exec(compile(source, filename, "exec", dont_inherit=True),
File "core/scripts/userscripts/webcite.py", line 125
faCitationPattern = ur'\{\{\s*یادکرد(?:\{\{.*?\}\}|.)*?\}\}'
[1]
https://github.com/PersianWikipedia/fawikibot/
blob/master/webcite.py
_______________________________________________
Wikimedia Cloud Services mailing list
Cloud(a)lists.wikimedia.org (formerly labs-l(a)lists.wikimedia.org)
https://lists.wikimedia.org/mailman/listinfo/cloud
_______________________________________________
Wikimedia Cloud Services mailing list
Cloud(a)lists.wikimedia.org (formerly labs-l(a)lists.wikimedia.org)
https://lists.wikimedia.org/mailman/listinfo/cloud
_______________________________________________
Wikimedia Cloud Services mailing list
Cloud(a)lists.wikimedia.org (formerly labs-l(a)lists.wikimedia.org)
https://lists.wikimedia.org/mailman/listinfo/cloud
--
Guilherme P. Gonçalves