correct way to check for True in __builtins__?

David LeBlanc whisper at oz.net
Fri May 10 19:48:33 EDT 2002


how about:

try
	dir(True)
except
	...

which should return a fat list (which you need not care about) on 2.2.1 and
later and choke on 2.2.0 and earlier no?

David LeBlanc
Seattle, WA USA

> -----Original Message-----
> From: python-list-admin at python.org
> [mailto:python-list-admin at python.org]On Behalf Of Mark McEahern
> Sent: Friday, May 10, 2002 16:26
> To: Python
> Subject: correct way to check for True in __builtins__?
>
>
> I want to check whether True is builtin and I thought I'd be clever by
> saying:
>
> 	if True not in __builtins__:
> 		True = bool(1)
> 		False = bool(0)
>
> of course, __builtins__ doesn't seem to be built to be accessed that way.
>
>   http://mail.python.org/pipermail/pythonmac-sig/2001-April/003285.html
>
> I could also do:
>
> 	import sys
> 	# examine sys.version_info tuple, if it's less than 2, 2, 1...
>
> Or:
>
> 	if True in dir(__builtins__):
> 		...
>
> Is there a preferred way to do this?
>
> Thanks,
>
> // mark
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list






More information about the Python-list mailing list