Numbers and truth values

John Nagle nagle at animats.com
Sat Apr 28 14:35:36 EDT 2007


Steven D'Aprano wrote:
> On Sat, 28 Apr 2007 15:36:19 +0200, Szabolcs wrote:
> 
> 
>>>>>>True = 2  # DON'T DO THIS!!!
>>>>>>2 == True
>>>
>>>True
>>>
>>
>>But shouldn't Python forbid this? Is it possible to get a warning when 
>>unintentionally redefining built-in thing?
> 
> 
> Python forbids very few things in comparison to other languages. The
> attitude is "We're all adults here". Because Python is such a dynamic
> language, it is often hard for the compiler to tell the difference between
> something you are doing deliberately and a mistake.

     I'd have to consider that a bug.

     Some very early FORTRAN compilers allowed you to redefine
integer constants:

	
	CALL SET(25,99)
	WRITE (6,100) 25
     100 FORMAT(I6)

	SUBROUTINE SET(IVAR, INEWVAL)
	IVAR = INEWVAL

would print

     99

     It was generally agreed by 1970 or so that this was a bad idea,
and was taken out of the language.

     C originally didn't have a Boolean type, and it took years to
get that in and uniformly defined.  But in the end, "true" and
"false" were reserved words.

     "True", "False", and "None" should be reserved words in Python.
"None" already is.

				John Nagle






More information about the Python-list mailing list