Thursday, February 7, 2008

I didn't know about Python signal handling before. I think I lost a lot of my cockiness and feel much more humble now.

I was browsing these 15 exercises for learning a new programming language. I attempted this in Python: "Display series of numbers (1,2,3,4, 5....etc) in an infinite loop. The program should quit if someone hits a specific key (Say ESC key)." Really trivial execise, right?I've done the exact same thing in C about a goddamn decade ago using getchar. I realized that I don't know the Python equivalent. Googling gets me kinda unrelated stuff like marriage without sex! Hmm. Ok. Then I came across this good example. Then I wrote this: Pgm1. It calls that fn when Ctrl-C is pressed.

Miles to go still...

1 comment:

Anonymous said...

Why not use a try and except to catch a keyboard interrupt?

And btw oddly enough I just wrote a getchar function in python:)