web2py scripts (homemade task queues) and python2 compatibility

69 views
Skip to first unread message

Tom Clerckx

unread,
Jul 4, 2019, 11:41:45 AM7/4/19
to web2py-users
Can anyone confirm that backward compatibility with python2 is broken with respect to web2py scripts (or homemade task queueus)?
I just downloaded version "2.18.5-stable+timestamp.2019.04.08.04.22.03" and it looks like the python3 print() function must be used.

Is there any plan to fix this? If not, it would be good to include this information in the web2py book.


Test01:
=====
script "applications/examples/scrips/script01.py" containing only one line:
print("Test print")

This one executes fine when running:
python web2py.py -S examples -M -R applications/examples/scrips/script01.py


Test02:
======
script "applications/examples/scrips/script01.py" containing only one line:
print "Test print"

This one fails fine when running:
python web2py.py -S examples -M -R applications/examples/scrips/script01.py

Traceback (most recent call last):
  File "/home/tclerckx/Downloads/web2py/gluon/shell.py", line 275, in run
    execfile(startfile, _env)
  File "applications/examples/scrips/script01.py", line 1
    print "Test print"
                     ^
SyntaxError: invalid syntax

Nico Zanferrari

unread,
Jul 4, 2019, 4:45:30 PM7/4/19
to web...@googlegroups.com
Hi Tom,

even the latest  2.18.5 version of web2py is still fully compatible with Python 2.7.

I think you're running both of your tests with python 3 ;-) 
Another possibility is that you've first run your web2py framework with python 3 and then with python 2 -  you cannot mix them without cleaning up caches and dbs... Try test02 a fresh copy of the web2py sources, after being sure to use python2!

Nico

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/4c095bb7-1cd8-47a2-9b71-94a735dd5681%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tom Clerckx

unread,
Jul 5, 2019, 9:01:11 AM7/5/19
to web2py-users
Hi Nico,

I tried explicitly with python2.7, by executing: 
python2.7 web2py.py -S examples -M -R applications/examples/private/script01.py

On a fresh downloaded version of web2py.
Same result.

In web2py/gluon/shell.py, I notice the following first line:
from __future__ import print_function

Funny enough, it's only trough an external script that I'm getting this error.
Using the print statement in a controller function, everything works as expected.
So I believe it's only when running an 'external' script through web2py/gluon/shell.py that the print() function must be used.

Or am I missing something/making a mistake?

Best, Tom.
To unsubscribe from this group and stop receiving emails from it, send an email to web...@googlegroups.com.

Tom Clerckx

unread,
Jul 11, 2019, 5:35:38 PM7/11/19
to web2py-users
Anyone else that can shed some light on this?

Leonel Câmara

unread,
Jul 16, 2019, 12:48:41 PM7/16/19
to web2py-users
You're right, you must use the print function because web2py now has a "from __future__ import print_function" which forces you to use the print function even in python2

Tom Clerckx

unread,
Jul 16, 2019, 5:16:44 PM7/16/19
to web2py-users
That's clear, thanks for the update.
Reply all
Reply to author
Forward
0 new messages