Checking whether bool is a type

Terry Reedy tjreedy at udel.edu
Sun Jul 27 17:43:34 EDT 2003


"Jan Decaluwe" <jan at jandecaluwe.com> wrote in message
news:3F2442B2.E660E97 at jandecaluwe.com...
> In my application I need to know whether bool is
> available as a type (in Python2.3) or not. I just
> realized I can use the following:
>
> jand> python
> Python 2.3c1 (#1, Jul 21 2003, 12:40:39)
> [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2
> Type "help", "copyright", "credits" or "license" for more
information.
> >>> type(bool) is type
> True
>
> jand> python2.2
> Python 2.2.2 (#1, Oct 16 2002, 19:59:11)
> [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2
> Type "help", "copyright", "credits" or "license" for more
information.
> >>> type(bool) is type
> 0
>
> Great isn't it ?!

If all you care about is differentiating between 2.2 and 2.3, yes.
But this raises NameError, I believe, on earlier verisons without
'bool' builtin.  What is wrong with using sys.version[:3] >= '2.3'?
(Anyone - has sys.version always been around?)

Terry J. Reedy








More information about the Python-list mailing list