the concrete jungle welcomes you to

How to exit the Python interactive shell (IMO) the correct way

In Programming on November 9, 2009 at 10:31 pm

And now for a bit of Python programming. Brought to you by a slow, procrastinating afternoon in the office.

I hate doing this:

>>> exit
Use exit() or Ctrl-Z plus Return to exit
>>> exit()

C:\>

Why can’t Python exit when I just type exit? Because typing anything in the shell without parenthesis ‘()’ will only display the variable value’s string repr. Can we fix this? Yes.

Create a sitecustomize.py module and put it somewhere in your Python import path (in my Windows box, for example, I saved it in C:\Python25\Lib\sitecustomize.py) with this code:

import sys
import __builtin__

def setrealquit():
    "Redefine builtins 'quit' and 'exit' to actually exit when entered in the shell"
    class RealQuitter(object):
        def __repr__(self):
            self()
        def __call__(self, code=None):
            try:
                sys.stdin.close()
            except:
                pass
            raise SystemExit(code)
    __builtin__.quit = RealQuitter()
    __builtin__.exit = RealQuitter()

def main():
    setrealquit()

main()

The sitecustomize module will be imported every time the python shell is launched. This will basically replace the builtin quit and exit objects with our own ‘quitter’ that simply exits when it’s __repr__ method is called. You can override any builtins here, if you want (but remember, with great power comes great responsibility)

Pattern Recognition

In Film on November 1, 2009 at 2:05 am

SPOILER ALERT. Don’t read this post if you haven’t and would like to read the novel, Pattern Recognition by William Gibson.


Just finished reading William Gibson’s Pattern Recognition. It is a wonderful novel, I am instantly in love with it. Cayce Pollard has got to be the most interesting character I’ve come across in a long time, I think I’m in love with her too.

It is being adapted into a film. And I have several concerns regarding this. No, I am not against it being film-ized, in fact, I feel like it should be, in a way. My concerns are:

  1. Casting. I find the description of Cayce Pollard to be intentionally ambiguous. She is anti-fashion, unbranded, and very minimalistic, I feel the casting must also reflect this. But I am afraid Hollywood would not get this and will cast a big actress instead. Also, the only physical description of her in the book, “Helmut Newton’s nude portrait of Jane Birkin,” isn’t convincing enough (she is describing how another person, in the book, sees her, not Gibson) – it is hard to pin her down, and this might cause any casting decisions to be a disappointment.
  2. The Footage. The Footage is the heart of the book. It essentially is the book. It is profoundly beautiful and magical. Not just aesthetically, but also technically. SPOILER (highlight to view): This is because it is being produced and edited on the fly by a brain-dead person with a piece of metal lodged in her brain. How on earth would a director adapt that in real life?
  3. Email and forum threads. A chunk of “dialog” in the novel are emails, chat and forum threads. How do you do this on screen? Show screenshots of Hotmail? Have Cayce read her emails out loud or in her head? How?
  4. Product placement. I just hope they don’t go overboard with this. Ironically, although there are many brands and companies mentioned in the novel, it is only to say how Cayce is allergic to most of them.

That’s about it. So who can direct this? Peter Weir was on board at first but didn’t come through. A newer, more contemporary director perhaps? Someone who’s more versed in the internet, digital age of filmmaking maybe? I was thinking of Neil Blomkamp. I don’t know.

People who are the same age as me but famous and more successful

In Lain-lain on March 16, 2009 at 3:17 am

I’ve been mentally listing a lot of “holy crap, that person’s my age and has already done that?” moments these past few years. Now with the help of Wikipedia, I can rest assured that there is an official, interweb-sanctioned version of this sorry (for me) list.

This is just a partial preview. Click here to view the full list.

  1. Jessica Biel, American actress
  2. Dmitry Chaplin, Russian So You Think You Can Dance finalist
  3. Lee Chong Wei, Malaysian badminton player
  4. Kelly Clarkson, American singer
  5. Elisha Cuthbert, Canadian actress
  6. Kirsten Dunst, American actress
  7. Fairuz Fauzy, Malaysian A1GP driver
  8. Anne Hathaway, American actress
  9. Ricky Kaká, Brazilian footballer
  10. Keiichiro Nagashima, Japanese speed skater
  11. Maria, WWE superstar
  12. Dennis Moran, American computer hacker
  13. Nana Ozaki, Japanese gravure idol
  14. Elena Paparizou, Greek-Swedish singer
  15. Anna Paquin, Canadian actress
  16. Missy Peregrym, Canadian actress
  17. Tiffany Pollard, reality television star
  18. Andy Roddick, American tennis player
  19. Seth Rogen, actor/writer
  20. Vadims Vasiļevskis, Latvian javelin thrower
  21. Kat Von D, Mexican-American tattoo artist
  22. Lil Wayne, American rapper
  23. Kimberly Wyatt, singer (The Pussycat Dolls)
  24. and many more

Wow, Seth Rogen’s my age? I can’t believe it, I love his movies! That’s funny, because I really feel that we would get along well. Like, we’d hang together well or something. I think he’d like me, you know? I’m sure alot of guys are like, “I’d like to hang out with that guy,” but I think he’d like to hang out with me, that’s the cool thing. You know what I mean?

This post was brought to you by a still-up-at-3am-coz-overslept-on-sunday instant noodle moment.