[GRASS-dev] Use Global variables at Scripts (Python)

Glynn Clements glynn at gclements.plus.com
Thu Feb 25 16:15:58 EST 2010


Luis Lisboa wrote:

> I'm programming a few Scripts and I would like to know How can I access some
> global variables value such as GRASS_DIR, MAPSET; LOCATIOn or even others
> that I defined (e.g. GRASS_TEMP). How can I load and access them? (I'm
> working with Python scripts for GRASS 7)

Environment variables can be accessed using e.g.:

	gisbase = os.environ["GISBASE"]
or:
	gisbase = os.getenv("GISBASE")

The main difference between the two is that the former raises an
exception if the variable doesn't exist while the latter returns None
(or a user-defined value specified by the second argument).

$GISRC variables (GISDBASE, LOCATION_NAME, MAPSET) can be accessed via
grass.script.gisenv(), e.g.

	import grass.script as grass
	env = grass.gisenv()
	mapset = env["MAPSET"]

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


More information about the grass-dev mailing list