Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Checking whether bool is a type

Reply
Thread Tools

Checking whether bool is a type

 
 
Jan Decaluwe
Guest
Posts: n/a
 
      07-27-2003
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-9] 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-9] 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
private.php?do=newpm&u=
http://jandecaluwe.com
 
Reply With Quote
 
 
 
 
Martin v. =?iso-8859-15?q?L=F6wis?=
Guest
Posts: n/a
 
      07-27-2003
Jan Decaluwe <> 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-9] 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
 
Reply With Quote
 
 
 
 
Christos TZOTZIOY Georgiou
Guest
Posts: n/a
 
      07-27-2003
On Sun, 27 Jul 2003 23:22:58 +0200, rumours say that Jan Decaluwe
<> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
enum promote to bool type rather than Integer type? FE C++ 6 08-04-2009 03:21 PM
Checking whether a string contains only ISO-8859-1 chars Jonck Java 3 10-25-2004 12:45 PM
Checking Whether a Browser Accepts Cookies rsindall@zethics.com ASP .Net 1 10-08-2004 07:15 AM
checking whether browser allows cookies in asp.net Ollie ASP .Net 3 07-24-2004 09:33 PM
Checking whether an employee is microsoft certified. Stuart p Microsoft Certification 4 10-17-2003 06:22 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57