[GRASS-dev] Re: [GRASS-user] Get current location projection in a
Python Script
Nikos Alexandris
nikos.alexandris at felis.uni-freiburg.de
Thu Jul 22 03:44:19 EDT 2010
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()" )
Glynn Clements wrote:
> In this case, neither;
:D
> it's just converting strings to integers. The
> rows and cols values in the g.region output will always be integers.
Right... needles question (=I need to rest a bit).
> 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'
Thanks for details, Nikos
More information about the grass-dev
mailing list