Opened 11 years ago
Closed 7 years ago
#2288 closed defect (fixed)
Python3 compatibility changes
Reported by: | neteler | Owned by: | |
---|---|---|---|
Priority: | normal | Milestone: | 7.0.6 |
Component: | Python | Version: | svn-releasebranch70 |
Keywords: | python | Cc: | |
CPU: | Unspecified | Platform: | Unspecified |
Description
In Python 3 exception objects are only available via the "as" keyword, which was introduced in 2.6.
http://docs.pythonsprints.com/python3_porting/py-porting.html#exceptions
I have prepared two patches (relbr7 and trunk) which update all existing Python files accordingly. Files attached for inspection.
Attachments (2)
Change History (8)
by , 11 years ago
Attachment: | exception_fixes_relbr7.diff added |
---|
follow-up: 2 comment:1 by , 11 years ago
Replying to 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).
comment:2 by , 11 years ago
Summary: | Python3 compatibility: exception needs "as" keyword → Python3 compatibility changes |
---|
Replying to glynn:
Replying to 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.
comment:3 by , 9 years ago
Milestone: | 7.0.0 → 7.0.5 |
---|
comment:5 by , 8 years ago
Milestone: | 7.0.5 → 7.0.6 |
---|
Python3 patch for relbranch7