python - Define True, if not defined, causes syntax error -


i have found following construct today in elses code:

try: true, false except nameerror: true = 1==1; false = 1==0 

as understand this, defines true , false if not defined already. if defined shouldn't throw nameerror-exception, right?

i have tryed myself in shell , shows me syntaxerror: can't assign keyword

my question why shot syntax error if true , false defined? if true , false available on system, shouldn't go past exception handling , not show syntax error?

this code written python 2.x , won't work on python 3.x (in true , false true keywords).

since true , false keywords in python 3, you'll syntaxerror cannot catch.

this code exists because of old versions of python. in python 2.2 (released in 2001!), true , false did not exist predefined names, code provide compatible definitions later code use true , false.

when converting python 2.x code python 3.x, remove these lines; historical , have no use in python 3.x. if see these lines in else's code, sure sign program not written or ported python 3.


Comments

Popular posts from this blog

c# - Where does the .ToList() go in LINQ query result -

Listeners to visualise results of load test in JMeter -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -