# Conditional won't work on GrassGIS python script

I have a conditional in Python script from GRASS but I can not get it to work. No matter if I set m to 1 or 0 it always prints "m must be 1 or 0." like it won't enter the conditional.

Here's the script:

``````m=options['m']

if m==1:
grass.mapcalc("up=\$c+tan(\$phy)*((\$gamma*\$z*(cos(slope)^2))-(\$k*\$gamma*\$z*sin(slope)*cos(slope))-(\$z*\$gammaw))",
z = options['z'],
c = options['c'],
gamma = options['gamma'],
phy = options['phy'],
k = options['k'],
gammaw = 9.81)
print ('m is 1')
elif m==0:
grass.mapcalc("up=\$c+tan(\$phy)*((\$gamma*\$z*(cos(slope)^2))-(\$k*\$gamma*\$z*sin(slope)*cos(slope)))",
z = options['z'],
c = options['c'],
gamma = options['gamma'],
phy = options['phy'],
k = options['k'])
print ('m is 0')
else:
print("m must be 1 or 0.")
``````

## 1 Answer

You probably need to convert it to number:

``````m = int(options['m'])
``````

But it looks like you want to define it as a flag instead of option, since it can be only True or False, so then you would use it as:

``````if flags['m']:
# do something
else:
# do something else
``````

See also the manual: https://grass.osgeo.org/grass74/manuals/g.parser.html

• Thank you Anna, i did thought it was something simple but I was really stuck. Thanks for your help! – Federico Gómez Feb 20 '18 at 14:54