True

Peter Otten __peter__ at web.de
Mon Oct 20 06:09:45 EDT 2003


Andrew Bennetts wrote:

> On Sun, Oct 19, 2003 at 08:17:15AM -0700, David Eppstein wrote:
>> In article <3f929cf0$1_1 at themost.net>,
>>  "Paul Watson" <pwatson at redlinec.com> wrote:
>> 
>> > Then, what is the best way to write boolean operations for Python 2.1
>> > so that it will be as 2.3+ ready as possible?
>> 
>> I've been including the following at the start of some of my code:
>> 
>> if 'True' not in globals():
>>    globals()['True'] = not None
>>    globals()['False'] = not True
> 
> Why not simply:
> 
> try:
>     True
> except NameError:
>     True = (1 == 1)   # or not None, if you prefer
>     False = not True
> 
> Or were you trying to change the __builtins__ by using globals()?
> 
> -Andrew.

I suppose David tries to avoid a syntax error raised by the assignment

True = somethingElse

in a future version of Python. Therefore he has "hidden" the builtins to be
assigned from the compiler by turning them into strings.

Peter







More information about the Python-list mailing list