[GRASS-dev] grass.info versus print

Paulo van Breugel p.vanbreugel at gmail.com
Thu Apr 14 04:33:02 PDT 2016


On Thu, Apr 14, 2016 at 1:04 PM, Glynn Clements <glynn at gclements.plus.com>
wrote:

>
> Vaclav Petras wrote:
>
> > sys.stdout/print is the way. grass.script.info and others are for
> messages,
> > not output, and they go to stderr which might cause mixing of order with
> > stdout in GUI and I unfortunately don't know how to avoid it.
>
> grass.script.info() executes "g.message -i", which calls
> G_important_message(), which writes to stderr.
>
> In general, scripts should use the g.message wrappers rather than
> Python's "print" statement or os.write(), as that will honour any
> configuration options (GRASS_VERBOSE, GRASS_MESSAGE_FORMAT,
> --quiet/--verbose, etc).
>

Thanks Glynn. It seems there are different opinions, see earlier comment
from Vaclav. Also in the examples on the Wiki (e.g., on
https://grasswiki.osgeo.org/wiki/GRASS_and_Python) and various addons I
have looked at, I can see both being used. Perhaps the most important thing
is that one should avoid mixing the two, which is something that maybe
could go somewhere in the wiki?

In my script (r.vif), both approaches have an issue with how output is
displayed. Using grass.info() results in columns not being printed with
fixed width in the command output, while they are in the console. On the
other hand, when using print() empty lines are not printed. I personally am
not too much bothered by both, so if you think I should use grass.info() I
am fine with that.



>
> --
> Glynn Clements <glynn at gclements.plus.com>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20160414/ef7f735f/attachment.html>


More information about the grass-dev mailing list