...
Interpretation of the boolean is according to Tcl rules. These are very close to Python rules, however.
>>>
Code Block |
---|
>>> import tohil >>> tohil.tclobj(True) <tohil.tclobj: '1'> >>> tohil.tclobj(False) <tohil.tclobj: '0'> |
...
Code Block |
---|
>>> bool(tohil.tclobj(1)) True >>> bool(tohil.tclobj(0)) False |
...
Code Block |
---|
>>> tohil.tclobj('y') <tohil.tclobj: 'y'> >>> bool(tohil.tclobj('y')) True >>> bool(tohil.tclobj('t')) True >>> bool(tohil.tclobj('f')) False >>> bool(tohil.tclobj('F')) False >>> bool(tohil.tclobj('not-a-boolean')) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: expected boolean value but got "not-a-boolean" |
...
An example that uses most of the list methods:>>>
Code Block |
---|
>>> fruits = tohil.tclobj(['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']) >>> fruits <tohil.tclobj: 'orange apple pear banana kiwi apple banana'> >>> len(fruits) 7 >>> fruits.append('watermelon') >>> fruits <tohil.tclobj: 'orange apple pear banana kiwi apple banana watermelon'> >>> fruits.insert(1, 'cantaloupe') >>> fruits <tohil.tclobj: 'orange cantaloupe apple pear banana kiwi apple banana watermelon'> >>> fruits.pop() 'watermelon' >>> fruits.pop(5) 'kiwi' |
...