[GRASS-dev] [GRASS GIS] #2288: Python3 compatibility: exception needs "as" keyword

GRASS GIS trac at osgeo.org
Mon May 12 15:53:48 PDT 2014


#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  |  
-------------------------+--------------------------------------------------

Comment(by 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?

 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).

-- 
Ticket URL: <http://trac.osgeo.org/grass/ticket/2288#comment:1>
GRASS GIS <http://grass.osgeo.org>



More information about the grass-dev mailing list