[GRASS-user] loop import+merge

Glynn Clements glynn at gclements.plus.com
Tue Dec 14 18:04:07 EST 2010


Patrick_schirmer wrote:

> Thanks. That was what I was searching for so urgent!
> This one works even it might not be the nicest one:

A quick note on style:

>      i=1
>      n=1
>      i=str(i)

>      while n<5:
>          n=n+1
>          i=int(i)
>          i=i+1
>          i=str(i)

The main looping idiom in Python is "for ... in ...", e.g.:

	for n in xrange(1, 5):
	    i = str(n)

Also:

>          grass.run_command(
>              'v.patch',flags="-o",

flags="-o" isn't valid; it happens to work due to an implementation
detail, but that could change, and won't work if you need to use any
other flags. If you want to enable the --overwrite flag, use:

>          grass.run_command(
>              'v.patch', overwrite=True,

Similarly for --quiet and --verbose.

For now, the best references for the GRASS-Python scripting library
are its source code and the existing scripts in 7.0.

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


More information about the grass-user mailing list