This Is Worrying

March 19, 2007 at 2:49 am 2 comments


Last login: Sun Mar 18 22:39:27 on ttyp1
Welcome to Darwin!
ok-computer:~ p_trick$ python
Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> True, False
(True, False)
>>> __builtins__.True, __builtins__.False  = __builtins__.False, __builtins__.True
>>> True, False # oh dear
(False, True)
>>> if False: print "Oops."
...
Oops.

Is there a reason for this?

Entry filed under: code. Tags: .

Old School Five Things that Suck About Objective-C and Cocoa

2 Comments

  • 1. James  |  March 20, 2007 at 4:15 am

    Hey, that’s pretty neat. I didn’t know that was possible. But wait, why is it worrying?

    Just hitting enter for
    if False: print “Oops.”
    sends True normally. But since you’ve swapped Python’s definitions of True and False, it sends False. I don’t really see what the problem is.

    >>> x = True
    >>> x
    False

    Fun with bool!

  • 2. Carl  |  July 21, 2007 at 10:44 am

    In Py3000, True and False will become keywords exactly to prevent these sort of shenanigans… That said, it’s no big deal, because anyone foolhardy enough to redefine True and False should also know what they’re getting into…


About Me



I'm Patrick Thomson. This was a blog about computer programming and computer science that I wrote in high school and college. I have since disavowed many of the views expressed on this site, but I'm keeping it around out of fondness.

If you like this, you might want to check out my Twitter or Tumblr, both of which are occasionally about code.

Blog Stats

  • 649,962 hits

%d bloggers like this: