[GRASS-dev] [GRASS GIS] #2008: grass.script's find_program() can't find modules

GRASS GIS trac at osgeo.org
Wed Jun 19 05:29:23 PDT 2013


#2008: grass.script's find_program() can't find modules
-----------------------+----------------------------------------------------
  Reporter:  hamish    |       Owner:  grass-dev@…              
      Type:  defect    |      Status:  reopened                 
  Priority:  critical  |   Milestone:  6.4.4                    
 Component:  Python    |     Version:  svn-releasebranch64      
Resolution:            |    Keywords:  find_program()           
  Platform:  All       |         Cpu:  x86-64                   
-----------------------+----------------------------------------------------

Comment(by zarch):

 Replying to [comment:2 glynn]:
 > Replying to [comment:1 hamish]:
 > > actually it works, what I was missing what that the argument needed to
 be in [square] brackets. (why?)
 > Because it's a list of arguments to be passed to the program.
 >
 > It would be trivial to change the function, i.e.
 > {{{
 > -def find_program(pgm, args = []):
 > +def find_program(pgm, *args):
 > }}}



 Moreover insert a mutable object as default arguments it's dangerous and
 should be avoid, see the example below:


 {{{
 >>> def myfunc(mylist=[]):
 ...     mylist.append(5)
 ...     return mylist
 ...
 >>> myfunc()
 [5]
 >>> myfunc()
 [5, 5]
 >>> myfunc()
 [5, 5, 5]
 >>> myfunc()
 [5, 5, 5, 5]
 }}}


 Why not change the function in:


 {{{
 >>> def find_program(cmd):
 ...     return cmd in grass.get_commands()[0]
 ...
 >>> find_program('r.sun')
 True
 }}}

-- 
Ticket URL: <https://trac.osgeo.org/grass/ticket/2008#comment:5>
GRASS GIS <http://grass.osgeo.org>



More information about the grass-dev mailing list