[GRASS-user] Re: Trying python scripts.

Marcello Gorini gorini at gmail.com
Mon May 31 08:50:41 EDT 2010


>On Mon, May 31, 2010 at 5:39 AM, Daniel Lee <Lee.Daniel.1986 at googlemail.com
> wrote:
>Hi Marcello,
>
>Great that everything's working for you ;) I'm also a beginner and loving
GRASS and Linux... Anyway, 'nuff said. To Python: Your script worked in the
new >version? That means in the new 6-4?

Hello Daniel, how are you?
Yes, I mean https://svn.osgeo.org/grass/grass/branches/releasebranch_6_4 .
>I've also tried running Python scripts and have had problems, I ended up
switching over to shell scripts because my work was very time sensitive, but
I really >like working with Python and I know it better than shell
scripting. I noticed in your post earlier that you used the command:
>
>*>python myscript.py raster1=map1 raster2=map2 output=outmap*
>
>Following questions:
>- Is it necessary to input "python" in front of the script name?

No, you can use ./ only.

>- I was under the impression that Python scripts can be saved into the
script directory (*/opt/grass/scripts*, if I'm not mistaken, right now I'm
on another >computer so I can't check); is that necessary? If not, do you
just enter the entire path to the script?

Yes, you can also save it in the scripts directory and run it directly or
you can enter the entire path in terminal and ./script.

>- I was also under the impression, that since you tell GRASS what kind of a
script it is in the first line (*#!/usr/bin/env python*), that you don't
need to save it >as .py. Am I mistaken there?

You are also right. I renamed it without the .py extension and it worked as
well.

>I've always saved my python scripts into the script directory and then
tried to run them from the GRASS wxPython GUI. It always seemed to find the
script >and then fail to parse it correctly. Perhaps it was because I was
leaving off the "python" at the beginning of the command line; everything
else should be the >same, the script was executable, etc. Any other
thoughts? I sadly can't give any examples at the moment because I'm on
another computer and after my new >nstallation I don't have the failed
script outputs as examples any more.

I saved it as r.myscript in the script directory and was able to run
directly from the gui or the terminal with no problems. So I guess it is not
because of the "python" in the command line. If your version is the same as
mine now, I would check the code itself. But I am really a beginner in
everything so I wouldn't listen to me very much.
At least, I think I showed you that you are right in everything. If you can
post some examples of your failed scripts later on, I (and everybody else)
could try them for you. It would be good for my learning as well.

>Thanks!
>Daniel

No, I thank you, since you are the first person I might be helping a little
little bit in this list. It is good to at least try to contribute.

Best regards,

Marcello.

2010/5/31 Marcello Gorini <gorini at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/grass-user/attachments/20100531/70627b0b/attachment.html


More information about the grass-user mailing list