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

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()


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 module and put it somewhere in your Python import path (in my Windows box, for example, I saved it in C:\Python25\Lib\ 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):
        def __call__(self, code=None):
            raise SystemExit(code)
    __builtin__.quit = RealQuitter()
    __builtin__.exit = RealQuitter()

def 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

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.

Michael Crichton, 1942 – 2008

Michael Crichton has died of cancer at age 66.

He was the first author I read. I was probably ten or eleven, I was at my grandparents’ house in JB, of all places. Somebody left a copy Congo. It was an old, wrinkled copy. I read the first few pages and hardly understood a word, I was unaware of it at that time, but I was hooked – I went on and read almost all of his other books.

Until today I do not really know who’s copy of Congo that was, I suspect my mother probably borrowed from an uncle, or someone.

A year or two later Jurassic Park came out. The whole family went and saw it. I recognized the name Michael Crichton in the credits, but I also saw another name – Steven Spielberg, who was credited as the “director”. At that time I didn’t really know who Steven Spielberg was but I asked my father what does a director do. He said he was the person who’s in charge of the movie – the person who made the movie. So that was the first moment I learnt that movies were made, and were made by a person. There and then I told my father I wanted to be a director. But well, I didn’t. The point is I wouldn’t have known about making movies if it weren’t for Michael Crichton and his stories.

So thanks Michael for all the stories. Alas, you’ve really left us.

(And to cheer things up, here’s the obligatory xkcd comic)

No, its been over 15 years, buddy.

No, it's been over 15 years, buddy.

Malaysia — Epic WIN

I have a confession: I did not vote. So, although I am immensely proud of Malaysia for the first time ever (yes, this beats climbing Everest or hosting the best Commonwealth Games ever), every time I express my excitement or think about how EPIC this is, I will always get a pang of guilt and regret that somehow I’m not really part of it.

So now, I promise, I swear I will register and vote at the next election (or by-election if it happens). Not only that, I promise I will not be afraid to talk politics. I will be as active as I can in understanding and engaging in the (rightfully open) discourse of the governance of my country. Because, for the first time I can see that yes, I, a lonely guy who stays in his room all day writing a blog that nobody reads — can actually make a difference.

A friend once asked me, what did I want out of life. I asked him what did he mean, he said, “You know, like a big house ke, a sports car ke, whatever lah.”

I thought for a while, and answered — I want to change the world.

So this is my chance. This is our chance.

Movie Ideas #73-77

Presenting my latest set of movie-film ideas, numbers 73 – 77*

Untitled Horror/Thriller
A blogger commits suicide on a live webcam chatroom, shocking the entire web community. But mysteriously, her blog, Facebook profile and statuses are kept updated with cryptic messages. An elaborate prank? Or digital messages from the afterlife?

Untitled Romantic Comedy
A man with a rare speech disorder falls in love with a lip-reading deaf girl.

“KL Berhenti” Action/Drama (tentative title)
Due to a freak calendrical coincidence, the Hari Raya, Chinese New Year and Deepavali holidays are scheduled back to back. Last minute shopping spree craziness causes the problematic KL traffic system to buckle, engulfing the entire city in a rare mass bumper-to-bumper traffic jam. Watch as the normally disparate lives of Malaysians collide in the sizzling heat of KL streets.

“Strikeout” Action/Thriller (credit: original idea co-authored with Azim)
A psychotic fundamentalist threatens to blow up every single modern Malaysian landmark, from the Petronas Twin Towers, to the multi-million dollar Eye. An ex-bomb technician turn CID investigator, Johan Jufferi join forces with sultry TV reporter Sarimah Sarini to hunt down the KL Bomber. Will they be able to stop the madman before Malaysia is bombed back to the pre-Mahathir agricultural ages?

“Jalan-Jalan Cari Makan” Action/Crime (tentative title)
Four young Accounting BA graduates enter the job market, to find a highly competitive world. Jobless and desperate to make money, they unwittingly join the KL underworld – becoming Ah Longs. Follow the yuppie-wannabe middle-class suburban quartet as they journey into the underbelly of Kuala Lumpur, asking people for money – and making sure their taxes are properly accounted for.

This post was brought to you by large amounts of Nescafe Mocha Latte.

* The numbers 73-77 are not literal numberings representing any sort of real list, just a random set of numbers pulled out of my ass to signify the metaphorically long list of unfulfilled thoughts occupying my rarely explored, suppressed creative subconscious.

Google to launch OpenSocial — one API to rule them all (social networks that is)

Via TechCrunch:

The new project, called OpenSocial, goes well beyond what we’ve previously reported. It is a set of common APIs that application developers can use to create applications that work on any social networks (called ‘hosts’) that choose to participate.

Note, “on ANY social networks that choose to participate.” Currently the participating networks are: Orkut, Salesforce, LinkedIn, Ning, Hi5, Plaxo, Friendster, Viadeo and Oracle.

Nope, no Facebook. I guess the idea is to “out-open” Facebook. Great, just when I’m getting my feet wet thinking about developing Facebook apps. More details on the TechCrunch page.

You can now register [you].MY domains

Good news. MYNIC is planning to open registrations for .my 2nd Level domain names (e.g. Finally.

I can think of a whole slew of possible cool names that can go with .my. I’m not going to say what, I’m sure you can think of a few words (think domain naming “tricks” like :))

For those who already own .(com/net/org/edu).my domains, there will be a “priority period” of two months (Nov – Dec 2007) where you can automatically register your equivalent .my domain.

Public registration for Malaysians opens March 2008, with worldwide registration opening at least 6 months later.

Yes, imagine how much money you can make selling .my domains worldwide! My oh my.

There’s a FAQ with all the relevant details.


Get every new post delivered to your Inbox.