Ticket #4693 (closed defect: fixed)
Improve support for python3
| Reported by: | antonio | Owned by: | hobu |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.10.0 |
| Component: | PythonBindings | Version: | svn-trunk |
| Severity: | normal | Keywords: | |
| Cc: |
Description
There seems to be still some issue with python 3 support:
Iteration OGR Layers:
In [60]: for f in layer:
....: print(f)
....:
----------------------------------------------------------------
TypeError Traceback (most recent call last)
/home/antonio/<ipython-input-60-57e8d963b9b0> in <module>()
----> 1 for f in layer:
2 print(f)
3
TypeError: iter() returned non-iterator of type 'Layer'
GDAL sub-datasets:
In [63]: ds1.GetSubDatasets()
--------------------------------------------------------------
AttributeError Traceback (most recent call last)
/home/antonio/<ipython-input-63-674e513f6408> in <module>()
----> 1 ds1.GetSubDatasets()
/usr/lib/python3/dist-packages/osgeo/gdal.py in GetSubDatasets(self)
685
686 i = 1
--> 687 while sd.has_key('SUBDATASET_'+str(i)+'_NAME'):
688 sd_list.append( ( sd['SUBDATASET_'+str(i)+'_NAME'],
689 sd['SUBDATASET_'+str(i)+'_DESC'] ) )
AttributeError: 'dict' object has no attribute 'has_key'
sys.maxint is gone (and also a missing sys import)
In [64]: layer[0:1e500] ------------------------------------------------------ NameError Traceback (most recent call last) /home/antonio/<ipython-input-64-ef4e5319f766> in <module>() ----> 1 l[0:1e500] /usr/lib/python3/dist-packages/osgeo/ogr.py in __getitem__(self, value) 1533 if isinstance(value, slice): 1534 output = [] -> 1535 if value.stop == sys.maxint: 1536 1537 NameError: global name 'sys' is not defined
Please find attached four patches that should fix issues described above. I would appreciate a lot the review of another developer before committing.
Also there are some remaining pyflakes warnings. I don't know how to address them exactly:
$ pyflakes "ogr.py" ogr.py:760: undefined name 'OGRError' ogr.py:781: redefinition of function 'DeleteLayer' from line 452 $ pyflakes "gdal.py" gdal.py:770: redefinition of function 'WriteRaster' from line 733 gdal.py:823: redefinition of function 'BeginAsyncReader' from line 743 gdal.py:1089: local variable 'shape' is assigned to but never used
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

