[GRASS-user] Call an external function from GRASS-Pythons Scripts

Hi

I’m developing a small GRASS Python script but I will need to call an external executive. I already know where to put it (at $PATH) but i don’t know how to call it from Python GRASS Script. How can I do this? (as an example it’s helloWorld :slight_smile: )

Thanks
Best regards
Kim

Hi,

2010/4/22 Kim Besson <kimbesson1981@gmail.com>:

I'm developing a small GRASS Python script but I will need to call an
external executive. I already know where to put it (at $PATH) but i don't
know how to call it from Python GRASS Script. How can I do this? (as an
example it's helloWorld :slight_smile: )

grass.call()

e.g.

grass.call(['whoami', '--version'])

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa

Hi,

2010/4/22 Kim Besson <kimbesson1981@gmail.com>:

From http://download.osgeo.org/grass/grass6_progman/core_8py_source.html I
see that besides the main argument there is **kwargs. What is this?

all defined arguments from Popen

http://download.osgeo.org/grass/grass6_progman/classpython_1_1core_1_1Popen.html

Martin
--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa

Hi,

{please keep discussion on ML}

2010/4/22 Kim Besson <kimbesson1981@gmail.com>:

Bur for instance you separated two argument inside . This means that for
instance If I need to call a external function and inser input and output I
would have to do this:
grass.call(['whoami', 'input_file', 'output_file']) or
grass.call(['whoami input output_file'])

it's first argument 'args'.

Martin

PS: Probably it would be reasonable to change configuration of ML
(send replay to the list instead to 'from') to avoid this mistake.

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa

Here now at the ML for everyone :slight_smile:
But which one of the two options is correct? The first one or the second one? Or both are ok? (at least the second one is correct I suppose)

2010/4/22 Martin Landa <landa.martin@gmail.com>

Hi,

{please keep discussion on ML}

2010/4/22 Kim Besson <kimbesson1981@gmail.com>:

Bur for instance you separated two argument inside . This means that for
instance If I need to call a external function and inser input and output I
would have to do this:
grass.call([‘whoami’, ‘input_file’, ‘output_file’]) or
grass.call([‘whoami input output_file’])

it’s first argument ‘args’.

Martin

PS: Probably it would be reasonable to change configuration of ML
(send replay to the list instead to ‘from’) to avoid this mistake.

Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa

Hi,

2010/4/22 Kim Besson <kimbesson1981@gmail.com>:

> would have to do this:
> grass.call(['whoami', 'input_file', 'output_file']) or
> grass.call(['whoami input output_file'])

if the syntax is 'cmd input output' then

grass.call(['cmd', 'input', 'output'])

see

http://docs.python.org/library/subprocess.html#subprocess.Popen

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa

Hi,

2010/4/22 Martin Landa <landa.martin@gmail.com>:

> would have to do this:
> grass.call(['whoami', 'input_file', 'output_file']) or
> grass.call(['whoami input output_file'])

if the syntax is 'cmd input output' then

grass.call(['cmd', 'input', 'output'])

see

http://docs.python.org/library/subprocess.html#subprocess.Popen

or check existing GRASS scripts, e.g.

http://trac.osgeo.org/grass/browser/grass/trunk/scripts/v.in.e00/v.in.e00.py#L135

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa

On Thu, Apr 22, 2010 at 1:52 PM, Martin Landa <landa.martin@gmail.com> wrote:
...

PS: Probably it would be reasonable to change configuration of ML
(send replay to the list instead to 'from') to avoid this mistake.

Hi Martin,

I would strongly advise against that (see '90s archive for some damages
and OSGeo list archive too and others):

http://www.unicom.com/pw/reply-to-harmful.html
http://woozle.org/~neale/papers/reply-to-still-harmful.html

It is too risky. I have been asked several times in the past to remove
posting from a list archive which is not only a PITA but also a can
or worms (think censorship; which message to delete, which not etc.).

My strong 0.02 cents :slight_smile:
Markus

On Thu, Apr 22, 2010 at 1:52 PM, Martin Landa <landa.martin@gmail.com> wrote:
...

> PS: Probably it would be reasonable to change configuration of ML
> (send replay to the list instead to 'from') to avoid this mistake.

On Thursday 22 of April 2010 15:36:37 Markus Neteler wrote:

Hi Martin,

I would strongly advise against that (see '90s archive for some damages
and OSGeo list archive too and others):

http://www.unicom.com/pw/reply-to-harmful.html
http://woozle.org/~neale/papers/reply-to-still-harmful.html

It is too risky. I have been asked several times in the past to remove
posting from a list archive which is not only a PITA but also a can
or worms (think censorship; which message to delete, which not etc.).

My strong 0.02 cents :slight_smile:
Markus

Markus,

I just read about this past debate. So, it is always better to use the "Reply
to Mailing-List" button (KMail here)?

Pohhh... I am really sorry if I caused any problem since I've always been
using the "Reply-to-All" for the list and the "Reply-to" for personal
messages.

Nikos

Hi,

2010/5/5 Nikos Alexandris <nikos.alexandris@felis.uni-freiburg.de>:

[...]

I just read about this past debate. So, it is always better to use the "Reply
to Mailing-List" button (KMail here)?

Pohhh... I am really sorry if I caused any problem since I've always been
using the "Reply-to-All" for the list and the "Reply-to" for personal
messages.

AFAIU, "Reply-to-All" is OK.

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa

On Wed, May 5, 2010 at 5:30 AM, Nikos Alexandris
<nikos.alexandris@felis.uni-freiburg.de> wrote:

On Thu, Apr 22, 2010 at 1:52 PM, Martin Landa <landa.martin@gmail.com> wrote:
...

> PS: Probably it would be reasonable to change configuration of ML
> (send replay to the list instead to 'from') to avoid this mistake.

On Thursday 22 of April 2010 15:36:37 Markus Neteler wrote:

Hi Martin,

I would strongly advise against that (see '90s archive for some damages
and OSGeo list archive too and others):

http://www.unicom.com/pw/reply-to-harmful.html
http://woozle.org/~neale/papers/reply-to-still-harmful.html

It is too risky. I have been asked several times in the past to remove
posting from a list archive which is not only a PITA but also a can
or worms (think censorship; which message to delete, which not etc.).

My strong 0.02 cents :slight_smile:
Markus

Markus,

I just read about this past debate. So, it is always better to use the "Reply
to Mailing-List" button (KMail here)?

I don't know such button... (no KMail knowledge).

Pohhh... I am really sorry if I caused any problem since I've always been
using the "Reply-to-All" for the list and the "Reply-to" for personal
messages.

But "Reply-to-All" for the list and the "Reply-to" for personal messages
is perfect! Just go on. Nothing changed. I suggested to not change anything :slight_smile:

Markus

Martin Landa:
...

>> > PS: Probably it would be reasonable to change configuration of ML
>> > (send replay to the list instead to 'from') to avoid this mistake.

Markus Neteler:

>> I would strongly advise against that (see '90s archive for some damages
>> and OSGeo list archive too and others):
>>
>> http://www.unicom.com/pw/reply-to-harmful.html
>> http://woozle.org/~neale/papers/reply-to-still-harmful.html
>>
>> It is too risky. I have been asked several times in the past to remove
>> posting from a list archive which is not only a PITA but also a can
>> or worms (think censorship; which message to delete, which not etc.).

Nikos Alexandris

> I just read about this past debate. So, it is always better to use the
> "Reply to Mailing-List" button (KMail here)?

Markus Neteler:

I don't know such button... (no KMail knowledge).

Nikos Alexandris:

> Pohhh... I am really sorry if I caused any problem since I've always been
> using the "Reply-to-All" for the list and the "Reply-to" for personal
> messages.

Markus Neteler wrote:

But "Reply-to-All" for the list and the "Reply-to" for personal messages
is perfect! Just go on. Nothing changed. I suggested to not change anything
:slight_smile:

Nothing important, just for the records.

Reading (again) this thread: I extracted from the respective "debate" (I mean
the links posted by MarkusN [1][2]) that the "Reply to Mailing-List" button
(at least in KMail) adds some "special" header or something like that which is
the correct way to _reply_ in the list.

In addition, in the past I had asked Markus to remove some posts of mine (due
to a silly mistake) which was a really time-consuming and difficult process
(judging by Markus replies back then -- but I am so grateful he helped me out
-- thanks again Markus).

So, I felt for a moment bad thinking that I could have brought even more
problems in the list. Nevermind, it is good to know that there are no problems
using the Reply-to-All button.

Nikos

---
[1] <http://www.unicom.com/pw/reply-to-harmful.html&gt;
[2] <http://woozle.org/~neale/papers/reply-to-still-harmful.html&gt;