Hi Gazza,
The 'if' statement is on the right hand side of the '=' sign is actually a
ternary operator. Read the expression as :
if obj.get('battery_ok') == 'OK':
pkt['battery'] = 1
else:
pkt['battery']=0
(In python Numeric zero, None or False all evaluate to False, anything else
is true).
C++ has a similar operator ? : operator.
See https://www.python.org/dev/peps/pep-0308/ for the rational. Personally
I find it very confusing to use 'if' for both forms.
Hope this helps. Good luck.
Rob
On Monday, 25 May 2020 11:09:09 UTC+1, Gazza wrote:
>
>
> Hi Rob,
>
> I don't know much about python so can you explain how the new version of
> the battery status works as I still have to sort that for my mates station.
>
> if 'battery_ok' in obj:
> pkt['battery'] = 1 if obj.get('battery_ok') == 'OK' else 0
>
> If the received data is "battery_ok" : 1 ( or "battery_ok" : 0 for flat
> battery), what is the == 'OK' doing as it will never return a result of
> 'OK" ??
>
>
> Gaz
>
--
You received this message because you are subscribed to the Google Groups
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/weewx-user/662e5e8a-7cbb-4cac-af52-405abae5f1a4%40googlegroups.com.