[GRASS-dev] python percent() function: omit newlines?

Glynn Clements glynn at gclements.plus.com
Thu Oct 21 22:55:46 EDT 2010


Markus Neteler wrote:

> we have a small problem with grass.core.percent; which we use
> in a "for" loop. Unfortunately, calling the classical g.message,
> the percent() function issues with each output a newline.
> Since we work with very big map (around 350.000.000 cells),
> getting that number of newlines is, say, unfortunate.
> 
> I wonder if we need some "no newline" magic in g.message for this
> (ne flag?) or if we can clone percent() in lib/python/core.py to not write
> out a new line but to go just to the beginning of the line instead as
> it is done for the topology creation progress.

general/g.message/main.c:

    else if (percent->answer) {
	int i, n, s;
	i = n = s = -1;
	sscanf(message->answer, "%d %d %d", &i, &n, &s);
	if (s == -1) 
	    G_fatal_error(_("Unable to parse input message"));
	G_percent(i, n, s);
	fprintf(stderr, "\n");
    }

I really don't think that fprintf() belongs there; it should just call
G_percent(), without adding any "enhancements" of its own.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list