Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Checking whether bool is a type (http://www.velocityreviews.com/forums/t320180-checking-whether-bool-is-a-type.html)

Jan Decaluwe 07-27-2003 09:22 PM

Checking whether bool is a type
 
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 ?! Not sure whether I should consider
this to be completely obvious or very deep ...

Regards, Jan

--
Jan Decaluwe - Resources bvba
Losbergenlaan 16, B-3010 Leuven, Belgium
mailto:jan@jandecaluwe.com
http://jandecaluwe.com

Martin v. =?iso-8859-15?q?L=F6wis?= 07-27-2003 09:36 PM

Re: Checking whether bool is a type
 
Jan Decaluwe <jan@jandecaluwe.com> writes:

> 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 ?! Not sure whether I should consider
> this to be completely obvious or very deep ...


Very obvious.

Python 2.2.1 (#1, Sep 10 2002, 17:49:17)
[GCC 3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> bool

<built-in function bool>

bool is a function in Python 2.2.1+, not a type. It became a type only
in Python 2.3, see PEP 285.

Regards,
Martin

Christos TZOTZIOY Georgiou 07-27-2003 09:41 PM

Re: Checking whether bool is a type
 
On Sun, 27 Jul 2003 23:22:58 +0200, rumours say that Jan Decaluwe
<jan@jandecaluwe.com> might have written:

>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:


>>> type(bool) is type


You might like to do this as an alternative:

def bool_is_type():
try:
return isinstance(bool, type)
except NameError:
return 0

to catch older python versions as well.
--
TZOTZIOY, I speak England very best,
Microsoft Security Alert: the Matrix began as open source.


All times are GMT. The time now is 10:10 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.