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

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

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. www.something.my). 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 del.icio.us :))

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.

Siapa sini guna Meebo (or other web 2.0 apps)?

I use Meebo exclusively as my IM chat program.

My mother uses it too. She uses Flickr and some Google apps like Calendar. She sent me an SMS one day asking for help on Photoshop, I sent her a link to Picnik, she never asked me for Photoshop help again.

This is significant because my mother had never used a computer only after recently (since like a year ago actually). So this proves (to me at least) that those “web 2.0″ sites really do care about better user experience, and about making things easier for the user, and they do work.

But that’s not my point.

My point is, besides my mother, I do not know anyone else who uses these kind of web apps who are geographically near me (like in Malaysia). Only a handful. Except on Flickr, there are a lot of Malaysians there for some reason (Flickr being one of the first 2.0 sites, I guess). No, Friendster and MySpace users do not count. I’m talking about new, cutting edge sites that get featured in TechCrunch and has those beta logos.

So, consider this an unscientific survey. I picked three of my most used ones… (for those who are not familiar with any of them, I’ve written a short description)

Meebo Do you Meebo? Web-based Instant Messaging client. Supports MSN, Yahoo, GTalk, ICQ and AOL networks (practically all of them). All you need is to open meebo.com in your browser, no need to download any IM applications.
Reddit Are you on Reddit? A social bookmarking site, similar to Digg but better (IMO), and a bit less popular (IMO). You submit interesting links and people can vote it up or down, links with more upvotes get to the front ‘hot’ page.
Twitter Are you a Twit? “Micro” blogging. You update small 140 character snippets of what you’re doing right then. So people can learn how boring your life is. Learn how boring my life is at twitter.com/zaim

So if you are on any one of these websites, please tell me, drop a comment, e-mail or Meebo me. So that we can, um, well I’m sure what we can do then…

[ And, please don't be shy, drop a comment. From my WP.com blog stats, I know my posts usually get one or two hits from search results, PPS or Fakapster and whatnot. So if you are that one person, do comment, I'm really curious :) ]

“Ipoh Mali”, Pete Teo glocalism and thoughts on Television

So, Point Blank comes up with “Ipoh Mali”. What’s apparently so special, cutting edge, new and refreshing about this is its local (i.e. Malaysian) references. They say it like it’s never been done before. To this, I have to say, and pardon my abbreviated French, WTF?

You’re a Malaysian from Malaysia, what else do you want to sing about? Shouldn’t it come naturally instead of exceptionally. It’s almost perverse, I tell you.

You want local references? Take Pete Teo. Don’t let his song titles fool you, you know with him singing names like Marianne, Laura Nelson, Tom, etc. His songs ooze Malaysian-ness. Consider Carnival Hall:

See the seasons they don’t change around here,
The rain wash down all through the long hot years,
And the lions,
Well, they’ve all gone and disappeared,
The righteous lies deep in the ground.

God knows who the lions and the righteous he’s referring to. Take another one of his songs, Last Good Man, which he couldn’t seem to put to record on any of his albums (which is a shame, it’s one of my favourites):

Tidal waves in a monsoon drain,
The waiting hour will never be the same again,
Since the rain came, it’s been real strange.

Drinking Guinness in a Milo can,
Walking down Cyprus Avenue with pennies in my hand,
And from a backstreet, came Uji Rashid.

Long, hot, rainy seasons. Uji Rashid. Sounds familiar? Which takes me to another point I’d like to make (or observe and opine, if you will) – Pete’s genius in mixing the sacred and the profane, the use of contradicting images.

Like in Last Good Man, how he swerves from rainy drains, to Guinness, to Milo, to Cyprus Avenue, to Uji Rashid. And how he mixes a-world-away (Cyprus Avenue) experiences with balik-kampung locality (Uji Rashid). Now THAT’s what I call glocalism.

Also, his contradictory images has never been as perceptible as in Television, his latest album. Like in Hide your Gun:

Who for spring and daffodils?
Who for wedding bells?
Who for saints and infidels?
Numbly staring down,
Down the barrel of a gun.

And in Laura Nelson’s Bridge:

Gecko sings blues from heaven
Dead men play jazz from hell
[...]
Shimmering in the night
The congregation has gathered here for some devil’s delight.
Church bells the are ringing
And congregation screaming, hallelujah!
As the bishop leaves before the gospel
An angel swings below.

And Tom (now, I don’t know who Tom is supposed to be, this is just my personal take on it):

Jesus walked on water or so that’s what they say,
And Mary played a crooked hand,
Joe, well he walked around and around,
And that’s Tom, my friend.

Tom, my friend. Get it? As in Tom is NOT My Friend? No? Well, guess it’s really just me then.

One last point on Television – and I’d like to thank the album’s engineers for doing this – “mastering without compression”. A.K.A the missing ingredient in music nowadays. A.K.A subtlety.

Now, I don’t know much about audio engineering, but I can appreciate this, albeit only understanding it rather superficially. So I can’t really explain it sufficiently here (plus I’m getting bored writing) except to point to an example: Listen to track 9, Blow.

Notice the tabla in the background? (I assume it’s tablas, maybe it’s not) Now notice how even if it’s barely discernible, you can actually more than hear it, you can feel it? I bet you if you listen to the song without the tablas, it’ll sound really weird, like a totally different song. That’s something you can only achieve by not compressing the sound zealously, and removing all the “low” parts, and amplifying the “high” parts – i.e. removing it’s “dynamic range”. That’s how they did it in the 70′s, before digital music. And that’s how music is supposed to be made, IMHO. Read these articles for a better explanation: “Everything Louder Than Everything Else“, “What Happened To Dynamic Range

More than just an audio engineering thing, subtlety here also applies to his songwriting. How he uses a plethora of musical instruments and musicians, but still pulling it off without sounding chaotic – everything jives in, sounding like one without you noticing them sounding like one.

And how his songs often break into different parts and beats in the middle without jolting you a bit. Or how he “introduces” new instruments. Like in Blow, around minute 3:00 you’ll hear eastern/middle eastern vocals (think Sting’s Desert Rose). Certainly a sudden surprise, but a pleasant, subtle one. It’s so uplifting, I almost cried. No, seriously :)

That’s it. It’s 4:05am, Monday morning. Good bye.

My two new favourite words

moribund

(adj) : approaching death; about to die; expiring; almost obsolete

soporific

(n) : something inducing sleep, esp. a drug
   ”the doctor prescribed a soporific to help him sleep.”

(adj) : tending to induce sleep
   ”the professor delivered a soporific lecture.”

As in: “Zaim’s moribund life induces soporific effects towards his family and friends”

Definitions from NinjawordsWiktionary

More word lists at my wordie.org page. Wordie is like Flickr, but without the photos.

Follow

Get every new post delivered to your Inbox.