[GRASS-dev] Re: [GRASS-user] Get current location projection in a
Python Script
Glynn Clements
glynn at gclements.plus.com
Thu Jul 22 02:35:26 EDT 2010
Nikos Alexandris wrote:
> Nikos Alexandris wrote:
> > > > > >> rows = int(grass.region()['rows'])
> > > > > >> cols = int(grass.region()['cols'])
> Is python's "int()" truncating or rounding up values? The question came to me
> while thinking of r.mapcalc's respective functions ( i.e. "int() != round()" )
In this case, neither; it's just converting strings to integers. The
rows and cols values in the g.region output will always be integers.
If you pass a floating-point value to int(), it will be truncated
(i.e. rounded towards zero):
> int(1.9)
1
> int(-1.9)
-1
If you pass a string containing a decimal point to int(), it will
raise an exception:
> int("1.9")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '1.9'
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list