[GRASS-dev] Default content for the "answer" to G_OPT_F_INPUT

Moritz Lennert mlennert at club.worldonline.be
Tue Apr 17 07:32:34 PDT 2018


On 17/04/18 16:21, Nikos Alexandris wrote:
> * Moritz Lennert <mlennert at club.worldonline.be> [2018-04-17 15:56:10 +0200]:
> 
>> On 17/04/18 15:31, Nikos Alexandris wrote:
>>> Dear developers,
>>>
>>> is there a way to set a string as the content of a default "answer" for
>>> the G_OPT_F_INPUT option? I am trying to identify potential cases in the
>>> grass-addons repository, but I am not sure I have seen something related.
>>>
>>> The G_OPT_F_INPUT offers a field to enter a filename. The default
>>> "answer", for the parser, will be the name of the file.
>>>
>>> In addition, a field to "enter values directly" is created. The
>>> description of this field is: "Enter file content directly instead of
>>> specifying a file. Temporary file will be automatically created."
>>>
>>> Can this field be filled with a pre-defined content?
>>> The use case is to expose, to the user, a pre-defined set of
>>> reclassification rules. These will help a beginner to get started,
>>> understand easier and modify rules as he sees fit.
>>
>> Use the 'answer' parameter:
>>
>> #% answer : myfilename
>>
>> Moritz
> 
> It works: it loads the content of an external file. Are we forced to use
> external files in such a case? Which means an extra file has to be
> shipped with the source code.
> 
> Can we not use an in-script hardcoded string for example?

Sure you can.

Use write_command() with stdin=text that you wish to feed into 
r.reclass. You can find several examples of its usage in existing scripts.

Moritz

P.S. Thanks to MarkusM for raising the point about file path difficulties...


More information about the grass-dev mailing list