[GRASS-dev] Re: [GRASSGUI] silly question - running a python script

Glynn Clements glynn at gclements.plus.com
Mon Jun 11 09:45:56 EDT 2007


Hamish wrote:

> > > Oh no:
> > > 
> > >     for arg in sys.argv:
> > >         args += arg+" "
> 
> 
> I have updated the g.parser help page Python example with the fixed args
> usage, but I notice the Perl example there (6.3cvs version only) is
> broken as well.
> 
> http://freegis.org/cgi-bin/viewcvs.cgi/grass6/general/g.parser/description.html
> 
> if( $ARGV[0] ne '@ARGS_PARSED@' ){
>     my $arg = "";
>     for (my $i=0; $i < @ARGV;$i++) {
>         $arg .= " $ARGV[$i] ";
>     }
>     system("$ENV{GISBASE}/bin/g.parser $0 $arg");
>     exit;
> }

Perl's system() supports both scalar and array context, so the array
version should be used. Also, Perl has exec(), which is preferable to
system()+exit().

> Also I notice a difference in the python version where main(): now ends
> with "return". Does this matter?

A "return" at the end of a method should be a no-op.

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-gui mailing list