Discovering Python

Despite my strong bias towards Ruby, I am finally learning Python.
I think functional nature of the Python is what makes it attractive to me. After spending a lot of time with Erlang and Ruby, I found Python to be an interesting hybrid.. kind of “in between” Ruby magic and pure functional feel of Erlang. I like the fact that pretty much all Ruby meta programming is still possible and on top of that Python has a very good support for functions, higher level functions, which makes is very interesting combination for me. For a few years now I’ve been hearing people talking about it, but it did not register with me until I started playing with it. One thing for sure I am going to put more time into it…

Functional Example (very Erlangish and Rubyish in the same time 🙂 )

In [21]: def wrapper(fun):
      ....:   def func(*args, **kwargs):
      ....:     print " begin execution %s " % (fun.__name__)
      ....:     fun(*args, **kwargs)
      ....:     print " finished execution %s " % (fun.__name__)
      ....:   return func
      ....: 

In [22]: def hello(msg):
      ....:   print "hello %s" % (msg)
      ....: 

In [23]: f = wrapper(hello)

In [24]: f("Alex")
 begin execution hello 
 hello Alex
 finished execution hello 

Advertisements