Hi people,
If this is not the correct place to post this problem, I apologize. In that case, please be gentle and point me to a better mailing list.
I'm coding a text editor in Qt that uses Python for macros. The problem I have is that want to use the bool type introduced in 2.3, but I can't see how to do this. On http://docs.python.org/api/arg-parsing.html the format units are described, but no bool is there.
I guess there are two possibilities. Either the documentation is not updated with the new format unit, or it doesn't exist.
If it doesn't exist, I guess I should use the int format unit and call the http://docs.python.org/api/boolObjects.html functions to see if this is actually a bool or not?
I hope you can help me with this question. Please CC me with answers, since I am not a member of this list.
Thanks,
Bo Thorsen.
"Bo Thorsen" bo@thorsen-consulting.dk wrote in message news:200503211054.49142.bo@thorsen-consulting.dk...
If this is not the correct place to post this problem, I apologize. In that case, please be gentle and point me to a better mailing list.
The general Python mailing list (pyrhon-list ?) also at python.org. Or comp.lang.python (the two are gated to each other). Or gmane.comp.python.general. Or google groups.
On Monday 21 March 2005 04:54, Bo Thorsen wrote:
If this is not the correct place to post this problem, I apologize. In that case, please be gentle and point me to a better mailing list.
You should be able to get answers to this kind of question on comp.lang.python (aka python-list at python.org). But I'll give you this one for free. :-)
I'm coding a text editor in Qt that uses Python for macros. The problem I have is that want to use the bool type introduced in 2.3, but I can't see how to do this. On http://docs.python.org/api/arg-parsing.html the format units are described, but no bool is there.
There is no format character for boolean, and you don't actually need one.
Recall that in Python, all objects have some interpretation as a truth value. The easiest way to check this from C code is to pass the object to PyObject_IsTrue() or PyObject_Not() (depending on the sense of the test you want, and how you want your code to read). The argument can be retrieved in your PyArg_ParseTuple*() call using the "O" format character.
If it doesn't exist, I guess I should use the int format unit and call the http://docs.python.org/api/boolObjects.html functions to see if this is actually a bool or not?
In most cases, you really don't care if the object is actually a bool. The recipe above will also work in older versions of Python. That lets you use bools for the reason they were really introduced: to enhance readability.
-Fred