[GRASS-dev] grass.info versus print

Paulo van Breugel p.vanbreugel at gmail.com
Mon Apr 11 11:48:43 PDT 2016


Hi Vaclav,


On 11-04-16 17:18, Vaclav Petras wrote:
> Hi, Paulo!
>
> On Mon, Apr 11, 2016 at 10:04 AM, Paulo van Breugel 
> <p.vanbreugel at gmail.com <mailto:p.vanbreugel at gmail.com>> wrote:
>
>     I want to provide the output formatted in three columns. I can use
>
>     nlength = 20
>     RES = [MAPy, vif, sqrtvif]
>     print '{0[0]:{1}s} {0[1]:8.2f} {0[2]:8.2f}'.format(RES, nlength)
>
>     This prints nicely on the command line. However, on the command
>     output tab of the GUI, the order of the printed lines is messed up.
>
>
> Mixing of order can happen in GUI when using both stderr and stdout. 
> What exactly is messed up? A minimal working example is probably 
> needed here.

Thanks for the help. The problem of mixed order of output was indeed 
because I was mixing print (stdout) and grass.info (stderr). The code is 
here: 
https://trac.osgeo.org/grass/browser/grass-addons/grass7/raster/r.vif/.

>
>     If I use instead:
>
>     nlength = 20
>     RES = [MAPy, vif, sqrtvif]
>     grass.info <http://grass.info>('{0[0]:{1}s} {0[1]:8.2f}
>     {0[2]:8.2f}'.format(RES, nlength))
>
>     It looks good on the command output tab, but it is printed without
>     the fixed width.
>
>
>
> sys.stdout/print is the way. grass.script.info 
> <http://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.

Following your pointer, I now replaced everything with print (I did not 
uploaded it yet) and now the columns display correctly on the console 
and in the command output tab of the addon GUI. Minor issue is that in 
the command output tab, empty lines are not printed.

The script  runs a loop, each time printing out a line with output. What 
I noticed is that if I use print, in the command output tab the output 
is all printed at once, while in the console, the output is printed one 
line at a time. Not really a problem, but I liked that the output is 
printed line by line, as that provides a sense of progress.

Cheers,

Paulo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20160411/d5b30f97/attachment-0001.html>


More information about the grass-dev mailing list