Category: python

Dissecting Python List allocator (CPython)

List is one of the most frequently used data structure in Python applications. The code for Python list object allocator is present in Python-2.7.5/Objects/listobject.c. Python allocates list objects in heap and uses underlying malloc based APIs. List is a container of Python object references. In plain C terminology. […]

Openstack swift: EADDRNOTAVAIL error

Problem swift-bench keeps EADDRNOTAVAIL error with a highly concurrency setting and multiple swift-bench clients. Setup Ubuntu 13, Swift single machine installation (refer SAIO), swift-client runs local with no-proxy mode. Solution EADDRNOTAVAIL stands for either unavailability of ephemeral ports and a known kernel bug. Check your range of ports: […]

Python Internals: Understanding Python data model (I)

Python sees everything as object. Every object has an identity, value and a type. Object identity and type are invariable. Object type determines if value is mutable or otherwise. Lifetime of object is based on reference count mechanism. Object Container Object containers are: list, dictionary, tuple, set. Containers […]

Parenthesize an expression in Python

    def pref(op):         print “called with op”, op         ret = -1         if op == ‘+’:             print “matched +”             ret = 1         if op == ‘-‘:             print “matched -”            […]

Pylucene- Part III: Hightlighting in Search

The search result can be customized to highlight the phrases that contain the requested keyword. The following code uses “Highlighter” class from Pylucene. We emit result in HTML formatted syntax. from lucene import \             QueryParser, IndexSearcher, IndexReader, StandardAnalyzer, \         TermPositionVector, SimpleFSDirectory, File, SimpleSpanFragmenter, Highlighter, \    […]