Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Saturday, June 12, 2010

Attending Singapore Google Technology Group Meetup

 

Today I attended this Singapore Google Technology User Group Meeting. It's my first time to attend such a Google meetings. Some of previous meet ups had always fallen on the wrong days -- on the day that I have something else to do. Today I am glad to be able to make it, attended the meeting, and Wesley Chun, was the speaker. He presented 2 sessions, one about Python and the other one about Google App Engine.

This guy's a hardcore Python guy, wrote the Core Python series of book, and was a presenter in the PyCon Asia Pacific 2010, Singapore -- an event that has been held last 3 days. Awesome in depth knowledge, vast industrial experiences, and keep the talk flows fluent.

The rest about the meeting can be found here: http://www.sg-gtug.org/2010/05/sg-gtug-special-tutorial-session-june.html

Thursday, July 9, 2009

Python's Lazy Evaluation on Exception Handling

I tried a simple code like this:

[sourcecode lang="python"]
try:
while True:
print('yipee')
except KeyboardInterrupt:
print('w00t')
[/sourcecode]

It runs successfully on command line interface, and keeps printing "yipee" until the user press Ctrl-C. After that I did a typo, which turns out to mistype the "KeyboardInterrupt" as "KeybaordInterrupt".

[sourcecode lang="python"]
try:
while True:
print('yipee')
except KeybaordInterrupt:
print('w00t')
[/sourcecode]

To my surprise, it still runs well, it keeps printing "yipee" to the screen. It's just that
when I press Ctrl-C, Python threw this error:

[sourcecode lang="shell"]
Traceback (most recent call last):
File '<stdin>', line 3, in <module>
KeyboardInterrupt
[/sourcecode]

During handling of the above exception, another exception occurred:

[sourcecode lang="shell"]
Traceback (most recent call last):
File '<stdin>', line 4, in <module>
NameError: name 'KeybaordInterrupt' is not defined
[/sourcecode]

I looked at the documentation of Python 3.1 which says:
The try statement works as follows.

First, the try clause (the statement(s) between the try and except keywords) is executed.

  • If no exception occurs, the except clause is skipped and execution of the try statement is finished.

  • If an exception occurs during execution of the try clause, the rest of the clause is skipped. Then if its type matches the exception named after the except keyword, the except clause is executed, and then execution continues after the try statement.

  • If an exception occurs which does not match the exception named in the except clause, it is passed on to outer try statements; if no handler is found, it is an unhandled exception and execution stops with a message as shown above.


The exception handling in Python works in a lazy manner, they will only validate the except clauses just before processing the exception!

Saturday, July 21, 2007

My Last Day,John Stovall, Python, WLST and Jython technology...

Yesterday supposed to be my last day @work. But somehow I must come again on Monday, and reschedule my flight to Batam to Tuesday. Moving to different kind of industry, but still in the same JEE/WebLogic/Solaris/Oracle path. Just a bit apart from the telco industry.

Lately I wasn't able to update this blog because at client office, they block the blog sites. Now, after being freed now I can start updating this blog again.

After accidentally meeting with John Stovall while at Changi Airport, I got enticed to learn more and more about Python, and Jython, its Java porting. First time I met John when I came to JaMU, December 2006. I was presenting Maven 2 technology, and each of the attendees were asked to introduce themselves. You can't miss noticing that big John. We happened to be in the same airplane, and after arrived at Changi airport, I began to recover his name, I called him, "Mr. Stovall", and then he began noticing an acquaintance. He's on the way to Amsterdam, to attend a Python meeting. He began preaching the beauty of Python, the philosophy behind it: "there should be one best way to do it...". I was also realizing that the reason why Guido von Rossum moved to Google was because of almost the entire Google site is based on Python.

I told John that I was using some Jython script because it is part of the WebLogic Scripting Tool (WLST). I learned a lot on it because some of my tasks while at Ericsson's project at Cyberjaya, was to create a automatic installation, deployment and setting tools. I found out that the best way to do it is through WLST. The older method wlshell still works, but using WLST, you could have access to a broader range of futures, both offline and online (requires a running WebLogic instance).

After returning to my regular tasks at Jakarta, I began downloading latest version of Jython. Before that, I have tried one of the scripting languages that has catch up the wave and has been ported to Java: JRuby. I also tried the scripting language made specially for Java: Groovy.

I began to fall in love working with Jython. You can utilize Java classes. The scripting language is close to the functional language I've been using a lot: Gofer+, a derivation of Haskell. Prof. Wishnu Prasetya taught us Data Structure and Algorithms using that functional language. Prof Mia Indika also taught the functional programming using the Haskell language. Python, er, Jython scripting more or less resemble that of Haskell. Sorry, for most of you who learned functional programming through typing lots of Irritating Parentheses (LISP). Though I also used Scheme when learning functional programming, later I mostly used the Gofer+/Haskell family of language.

Python also supports closure, so there is no point that Ruby is better. It only has Rails that makes it famous. I know when I learn Jython in depth, this is two fold, I could create better WLST scripts for WebLogic automatic deployments and configurations, and also be able to do OOP scripting for fast prototyping. I try to construct a script to test Hibernate DAOs and Managers. I will share some of these scripts when have more time to write it.