[GRASS-user] Re: Envoking GRASS in a python script
glynn at gclements.plus.com
Wed Oct 19 16:32:18 EDT 2011
> Just a couple of things, this...
> os.environ['PATH'] = os.pathsep.join(os.environ['PATH'],bindir,scriptdir)
> ...should have  around the arguments so as to make a list as the join
> function can take only one argument, so it looks like this...
> os.environ['PATH'] = os.pathsep.join([os.environ['PATH'],bindir,scriptdir])
Right. os.path.join() is a function named "join" in the os.path
module, and accepts multiple arguments. os.pathsep.join() is the
"join" method of the string class, called on the string os.pathsep,
and expects a single iterable as its argument. I got the two mixed up.
> And I had to set PYTHONPATH in my .bash_profile to get it to recognise the
> grass module, not sure why.
Python reads PYTHONPATH at startup, before executing the script.
Setting os.environ['PYTHONPATH'] won't have any effect upon the
current Python process, only upon processes descended from it.
However, you can modify sys.path directly, and that should affect
subsequent imports within the same script.
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-user