Update Python-Variable-Server-Client.md

Add a special note for Booleans
This commit is contained in:
dbankieris 2020-09-23 14:33:07 -05:00 committed by GitHub
parent 3f7ebd38e3
commit b2ec2313e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -142,6 +142,20 @@ Traceback (most recent call last):
ValueError: dictionary update sequence element #0 has length 1; 2 is required
```
### A Special Note for Booleans
All values from the variable server are strings, and in Python, the only string that converts to `False` is the empty string.
```python
>>> bool("0")
True
>>> bool("False")
True
>>> bool("")
False
```
Booleans come over the variable server as either “0” or “1”, so passing `type_=bool` will restult in the value always being `True`. Instead, just use `int`. In Python, an int with value 0 is false, and anything else is true, so it will work just fine in conditionals.
## Specifying Units
`get_value` has a parameter for that too: `units`.