Codeception

Musings & ramblings of a Pythonista

Demystifying Python's del, __del__ and garbage collection

People are often confused about Python's del keyword and __del__() method. Most people think that applying del on an object causes the object's __del__() method to be called. But this is not true. del keyword merely decrements the objects reference count and de-scopes the variable on its application. But it doesn't necessarily invoke the object's __del__() method. __del__ method will be called only when the garbage ...

Continue Reading...

IDEs vs. Text Editors: What should developers use?

The answer to this question may vary from developers to developers. I truly believe that it also depends on the kind of programming language they use for developing applications. For example, I have heard many times from my fellow Java programmers that they couldn't live without the Eclipse IDE, that they will not be able to write a working Java program with the help of a simple text editor ...

Continue Reading...

Simple file upload progressbar in PyQt

I've been learning the Qt Framework for the last few months and righfully it took the honour of being my favourite GUI toolkit ;-). But still I don't like KDE. I have used Tkinter for quite some time when I was studying engineering. But Qt is much more powerful than Tkinter and comes with an enormous bundle of GUI widgets and elements. Qt documentation is one of the best ...

Continue Reading...

Understanding Python variables and Memory Management

Have you ever noticed any difference between variables in Python and C? For example, when you do an assignment like the following in C, it actually creates a block of memory space so that it can hold the value for that variable.

int a = 1;

You can think of it as putting the value assigned in a box with the variable name as shown below.

int a =1;

And for all the variables ...

Continue Reading...

Pagination, Tags and more in Voldemort

Voldemort

I have been adding a few useul features to Voldemort for the last few months and it did come out pretty good. It now sports automatic Atom Feed and sitemap generation, thanks to the contibutions from my friend Stanislav Yudin. Here are the highlights.

Continue Reading...

Multiple Index queries in Riak using Python

Riak Logo

Riak is a Amazon Dynamo inspired masterless Key-Value store written in Erlang. It is one of those NoSQL databases that is rock stable, production ready and promises zero downtime. I have been using Riak at work and was literally blown away by its simplicity (Setting up a three node cluster wouldn't even take ten minutes) and the kind of support the Riak Community provides. And it is amazingly fast ...

Continue Reading...

Voldemort: A Jinja2 powered static site generator

Voldemort is a blog-aware static site generator inspired by Jinja2. All these times this blog was generated using Jekyll and I always wanted to use something Pythonic. Hyde was there, but the awesomeness of Jinja2 forced me to write Voldemort on my own.

Voldemort

Voldemort has its own advantages. You can templatize your HTML pages using Jinja and write posts using Markdown. And if you like this website, then you've ...

Continue Reading...

Packaging Python Applications

A few days ago, I came across a situation where I needed to create Debian packages for some Python libraries on which our software was dependant on. All these time we were creating and distributing the application as Eggs built using setuptools setup.py script. Later on this became a problem since some other applications which we were using were not Python applications and were packaged as .deb packages. This ...

Continue Reading...

Developing scalable services with Python

Developing multi-threaded applications in python is a "Pain In The Ass". And the GIL (Global Interpreter Lock) takes away the advantage of utilizing multiple cores in a machine. It doesn't matter how many cores a CPU have, GIL prevents threads from running in multiple cores. So python programs would't get the maximum performance out of the CPU when they use threads in their services.

In many cases you ...

Continue Reading...

Custom Authentication for Google App Engine apps

Google App Engine

Google App Engine is a widely used and most popular PaaS solution provided by Google. App Engine provides the developer with a wide range of apis which can be used to develop web applications using any WSGI compliant Frameworks (Webapp, Tipfy, Django, Bottle, Tornado etc.). One of the apis App Engine provides is the users api, which most of the developers confuses for an api which provides user creation, authentication ...

Continue Reading...

HyperGAE - Use Hypertable for App Engine Datastore

After few days of hacking on the Google App Engine SDK and ProtocolBuffers, finally I succeeded in creating a datastore driver for GAE that talks to Hypertable and stores the data there fully protocol buffer encoded. If you want to checkout this implementation head to HyperGAE repository and see files datastore_hypertable_ht.py and datastore_hypertable_thrift.py. HyperGAE basically uses two methods to connect to hypertable. Using the thrift api and using ...

Continue Reading...

Learn web development with Flask

I've seen many people jumping into web development with feature-complete frameworks like Django and Rails. But most of them will find it difficult to assimilate the web development concepts because of cluttered documentation (incase of Rails) or complexity (incase of Django). One might need to look at a simpler microframework to learn from scratch. And yes, Flask is the one you'd want to have a look at.

Flask ...

Continue Reading...

Cricinfo api (unofficial) for Python

Recently I started developing a Python library for accessing live information from ESPN Cricinfo like live scores, innings details and player profiles. Currently, it only fetches live match information using a simple Python iterator.

# instantiate
matches = CricInfo()
# iterate though matches
for match in matches:
    # match title
    print match.title
    # a short desciption for the match
    print match.description
    # url to live scorecard
    print match.link
    print match.guid

I wish ...

Continue Reading...

Borg Pattern

Singleton Design Patterns create all sorts of problems as you have exactly one instance for the singleton class throughout the program.

# Singleton implementation using new-style classes
class Singleton(object):
    def __new__(type):
        if not '_the_instance' in type.__dict__:
            type._the_instance = object.__new__(type)
        return type._the_instance

class Foo(Singleton):
    pass

>>> foo = Foo()
>>> bar = Foo()
>>> id(foo), id(bar)
(10049912, 10049912)

Usually programmers use Singleton Patterns as a global entry point ...

Continue Reading...

A commandline mapper

Python provides a builtin map function which applies a method over a list of entities. This function comes handy in a lot of situations as in

# find the square of all integers in a list
# Eg: 
#   input: [1, 2, 3, 4]
#   return: [1, 4, 9, 16]
map(lambda x: x*x, list_of_integers)

Similar functionality can be achieved in linux commandline using a combination of unix pipe | and xargs command. For ...

Continue Reading...