well first off you have a syntax error in the python script.
I am going to give you a quick rundown on python syntax.
Code: Select all
if eg.result = true:
print('enabled')
elif eg.result = false:
print('disabled')
unlike C or C++ python cares a whole lot about indenting and spaces. it is how it knows what to run and when.
Above is your python script
there are several things wring but we are going to first start off with the indenting, indenting can be any consistent use of 2+ spaces or the use of tabs.
In the world of EG we prefer to use 4 spaces because it doesn't make a very large tab arrow when using an IDE and 4 is just the perfect amount to be able to skim over code and be able to read how it is processed.
ok so back to the indenting.
it would appear as tho you intended the elif to be on the same indent level as the if statement. and if that is not the case you cannot start an if elif else chain with an elif. it must always start with an if
Code: Select all
if this:
run some code
elif that:
run some code
else:
run some code
ok so now that we established the importance of indenting
Code: Select all
if eg.result = true:
print('enabled')
elif eg.result = false:
print('disabled')
unlike C or C++ boolean objects are titled. so it would be
ok so onto the next step
Code: Select all
if eg.result = True:
print('enabled')
elif eg.result = False:
print('disabled')
equality testing. using a single "=" sign is for setting/declaring a variable.
== equal to
!= not equal to
> greater then
>= greater then or equal to
< less then
<= less than or equal to
there are many more operators but this gives the basic idea. the purpose of the operator is to return a boolean answer.
Code: Select all
test1 = 1
test2 = 1
test3 = 2
print test1 == test2
print test2 == test3
print test1 == test2 == test3
the last print statement above is going to print False. chaining expressions when compiled actually is the same as this
Code: Select all
print test1 == test2 and test2 == test3
it simply saves the fingers some work.
Code: Select all
if eg.result == True:
print('enabled')
elif eg.result == False:
print('disabled')
using == is not the wrong thing to do above. it is not the "Pythonic" thing to do.
Code: Select all
if eg.result is True:
print('enabled')
elif eg.result is False:
print('disabled')
ok so now the last thing is the print statement it's self.
In python 2 print is not a function call. no need to wrap the passed parameter with ()'s
Code: Select all
if eg.result is True:
print 'enabled'
elif eg.result is False:
print 'disabled'
Now to really tweak the bean a bit lets make this a one liner for the sake of being complete in this little tutorial.
Code: Select all
print 'enabled' if eg.result is True else 'disabled' if eg.result is False else '???'
when making this a one liner you cannot use elif. we also have to compete the if else chain. we can't leave it open ended as you can using multi line. which ends up as a do nothing scenario. in this case we always want to print something so we need to give the print statement something to output.