[GRASS-dev] Changes between Python 2 and Python 3 that might need attention in GRASS

On 13/01/14 16:13, Vaclav Petras wrote:>

One important change I stumbled upon recently is that integer
division results in float in python 3, while it resulted in integer
in python 2. So any module that relies on integer division resulting
in integer will need to be updated. I have no idea if such situations
exist, though.

If it is as you say, you may mention that in some separate email
thread and not hidden here in a wxPython GUI thread.

Your wish is my command ! :wink:

Here's the doc:

http://docs.python.org/3/whatsnew/3.0.html

Issues I think might need attention (but this is without verification within the grass python code):

- Print Is A Function
- Views And Iterators Instead Of Lists
- PEP 0238: An expression like 1/2 returns a float. Use 1//2 to get the truncating behavior.
- Text Vs. Data Instead Of Unicode Vs. 8-bit

Moritz

On Mon, Jan 13, 2014 at 4:25 PM, Moritz Lennert
<mlennert@club.worldonline.be> wrote:

Issues I think might need attention (but this is without verification within
the grass python code):

- Print Is A Function
- Views And Iterators Instead Of Lists
- PEP 0238: An expression like 1/2 returns a float. Use 1//2 to get the
truncating behavior.
- Text Vs. Data Instead Of Unicode Vs. 8-bit

Perhaps we can insert the following import statement in all the python
scripts that we want to make compatible with python3

from __future__ import (nested_scopes, generators, division,
absolute_import, with_statement, print_function, unicode_literals)

so we can start slowly to move from python2 => python3
what do you think?

Pietro

On Mon, Jan 13, 2014 at 11:48 AM, Pietro <peter.zamb@gmail.com> wrote:

On Mon, Jan 13, 2014 at 4:25 PM, Moritz Lennert
<mlennert@club.worldonline.be> wrote:
> Issues I think might need attention (but this is without verification
within
> the grass python code):
>
> - Print Is A Function
> - Views And Iterators Instead Of Lists
> - PEP 0238: An expression like 1/2 returns a float. Use 1//2 to get the
> truncating behavior.
> - Text Vs. Data Instead Of Unicode Vs. 8-bit

Perhaps we can insert the following import statement in all the python
scripts that we want to make compatible with python3

from __future__ import (nested_scopes, generators, division,
absolute_import, with_statement, print_function, unicode_literals)

so we can start slowly to move from python2 => python3
what do you think?

Thanks for the overview and suggestions, Moritz and Pietro. I added the -3
flag to python call somewhere in the makefiles, which checks at least the
basic things [r56821] (it runs when Python files are compiled to bytecode).

The `from __future__ import` is probably a good next step. But I would
start slowly, one reason is the manpower, the other is the lack of tests. I
would say that this can be checked when one is changing and testing the
module anyway (although it should be committed separately), not by one big
change for all modules.

Two questions. Is the `from __future__ import` Pietro provided save for
GRASS minimal Python version (probably 2.6)? And how 2to3 tool can help us?

Vaclav

[r56821] https://trac.osgeo.org/grass/changeset/56821
-3 : warn about Python 3.x incompatibilities that 2to3 cannot trivially
fix

Pietro

_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev