On Jul 15, 2008, at 10:42 PM, <[EMAIL PROTECTED]> <[EMAIL PROTECTED]
> wrote:
Message: 2
Date: Wed, 16 Jul 2008 04:14:44 +0100
From: Glynn Clements <[EMAIL PROTECTED]>
Subject: Re: [GRASS-dev] Python Scripting
To: "W. Chris Carleton" <[EMAIL PROTECTED]>
Cc: [email protected]
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=us-ascii
W. Chris Carleton wrote:
I'm trying to automate some modules in GRASS 6.3.2 using Python
scripts
and g.parser. I've had a look at the examples in /Scripts, but I'm
having some trouble. I want to pass arguments to a GRASS module by
iterating over a list of values. Here's what I have;
v.extract input="$GIS_OPT_INPUT" output="$GIS_OPT_OUTPUT""_"i \
type="point" layer=1 new=-1 list=i
The above is shell syntax.
In Python, it would look something like:
import subprocess
...
subprocess.call([
"v.extract",
"input=%s" % os.getenv("GIS_OPT_INPUT"),
"output=%s_%s" % (os.getenv("GIS_OPT_OUTPUT"), i),
"type=point", "layer=1", "new=-1", "list=%s" % i])
Glynn,
How do subprocess.call and subprocess.Popen compare for running GRASS
commands from inside Python scripts? Is call easier than Popen in this
context?
Michael
The main differences between Python and the shell:
1. All strings must be quoted.
2. Environment variables have to be accessed via os.getenv().
3. String manipulation requires explicit operators, e.g. +
(concatenation) or % (substitution).
4. Executing external programs requires the functions in the
subprocess module.
--
Glynn Clements <[EMAIL PROTECTED]>
_______________________________________________
grass-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-dev