#2288: Python3 compatibility: exception needs "as" keyword
-------------------------+--------------------------------------------------
Reporter: neteler | Owner: grass-dev@…
Type: defect | Status: new
Priority: normal | Milestone: 7.0.0
Component: Python | Version: svn-releasebranch70
Keywords: python | Platform: Unspecified
Cpu: Unspecified |
-------------------------+--------------------------------------------------
In Python 3 exception objects are only available via the
"as" keyword, which was introduced in 2.6.
Replying to [ticket:2288 neteler]:
> In Python 3 exception objects are only available via the "as" keyword,
which was introduced in 2.6.
We don't support anything earlier than 2.6, right?
In that case, the changes appear to be fine.
2.6 also supports the 3.x-style print() function, with
{{{
from __future__ import print_function
}}}
as well as the b'...' notation for byte-string literals.
So we can start using those.
It also supports the "with" statement, which should be used where
appropriate. Probably the most common use case is for file handling, i.e.
using e.g.
{{{
with open(filename) as f:
data = f.read()
}}}
rather than
{{{
f = open(filename)
data = f.read()
f.close()
}}}
The former has the advantage that the file will be closed in the event of
an exception (in the latter, the file will only be closed when the file
object is garbage-collected, which could be at any point up to program
termination).
Replying to [comment:1 glynn]:
> Replying to [ticket:2288 neteler]:
> > In Python 3 exception objects are only available via the "as" keyword,
which was introduced in 2.6.
>
> We don't support anything earlier than 2.6, right?
Right (as documented in REQUIREMENTS.html)
> In that case, the changes appear to be fine.
Submitted for relbr7 (r60217) and trunk (r60218).
Since further changes (as mentioned in #comment1) are needed I generalize
the ticket summary.