<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 14, 2016 at 7:33 AM, Paulo van Breugel <span dir="ltr"><<a href="mailto:p.vanbreugel@gmail.com" target="_blank">p.vanbreugel@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="">On Thu, Apr 14, 2016 at 1:04 PM, Glynn Clements <span dir="ltr"><<a href="mailto:glynn@gclements.plus.com" target="_blank">glynn@gclements.plus.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span>
</span><br>
In general, scripts should use the g.message wrappers rather than<br>
Python's "print" statement or os.write(), as that will honour any<br>
configuration options (GRASS_VERBOSE, GRASS_MESSAGE_FORMAT,<br>
--quiet/--verbose, etc).<br></blockquote><div><br></div></span><div>Thanks Glynn. It seems there are different opinions, see earlier comment from Vaclav.</div></blockquote><div><br></div><div>Perhaps I was not completely clear before. I agree with Glynn. grass.script.message() etc. for messages. print()/sys.stdout for text output (e.g. tables).<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>Also in the examples on the Wiki (e.g., on <a href="https://grasswiki.osgeo.org/wiki/GRASS_and_Python" target="_blank">https://grasswiki.osgeo.org/wiki/GRASS_and_Python</a>) and various addons I have looked at, I can see both being used.</div></blockquote><div><br></div><div>I would have to go through the individual examples but sometimes it might be be clear what is a message to inform user about something and what is a text output of the module. A rule of thumb can be that modules which output maps, (usually) don't do text output, so they shouldn't use print().<br><br></div><div>Also for you personal scripts, you are free to use any solution you want. That might be what the examples are showing. However, Python scripts which are modules, for example in Addons, should adhere to the submitting guidelines:<br><br><a href="https://trac.osgeo.org/grass/wiki/Submitting/Python#Messages">https://trac.osgeo.org/grass/wiki/Submitting/Python#Messages</a><br> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>Perhaps the most important thing is that one should avoid mixing the two, which is something that maybe could go somewhere in the wiki?<br></div></blockquote><div><br>Feel free to extent either wiki or guidelines if you think it is not clear enough.<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div></div><div><br>In my script (r.vif), both approaches have an issue with how output is displayed. Using <a href="http://grass.info" target="_blank">grass.info</a>() 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 <a href="http://grass.info" target="_blank">grass.info</a>() I am fine with that. </div></blockquote></div><br></div><div class="gmail_extra">First, always use the above guidelines to decide if print() or one of the g.message wrappers is the right solution. Second, look at the behavior in the command line (that's the canonical one). The GUI might get things wrong (and that might be bug).<br><br></div><div class="gmail_extra">Please, let me know what you think about it now,<br></div><div class="gmail_extra">Vaclav<br></div></div>