Uncategorized

Writing C in Cython

Computational Linguistics

For the last two years, I’ve done almost all of my work in Cython. And I don’t mean, I write Python, and then “Cythonize” it, with various type-declarations etc. I just, write Cython. I use “raw” C structs and arrays, and occasionally C++ vectors, with a thin wrapper around malloc/free that I wrote myself. The code is almost always exactly as fast as C/C++, because it really is just C/C++ with some syntactic sugar — but with Python “right there”, should I need/want it.

This is basically the inverse of the old promise that languages like Python came with: that you would write your whole application in Python, optimise the “hot spots” with C, and voila! C speed, Python convenience, and money in the bank.

This was always much nicer in theory than practice. In practice, your data structures have a huge influence on both the efficiency of your…

View original post 278 more words

Standard
Uncategorized

How to become a programmer, or the art of Googling well

Not particularly related to Python but still a good read for every programmer 🙂

okepi

*Note: Please read all italicized technical words as if they were in a foreign language.

The fall semester of my senior year, I was having some serious self-confidence issues. I had slowly come to realize that I did not, in fact, want to become a researcher. Statistics pained me, and the seemingly endless and fruitless nature of research bored me. I was someone who was driven by results – tangible products with deadlines that, upon completion, had a binary state: success, or failure. Going into my senior year, this revelation was followed by another. All of my skills thus far had been cultivated for research. If I wasn’t going into research, I had… nothing.

At a liberal arts college, being a computer science major does not mean you are a “hacker”. It can mean something as simple as, you were shopping around different departments, saw a command line for the…

View original post 1,398 more words

Standard
Uncategorized

How I satisfied a request from my friend with Python

IMPYTHONIST

You may have wondered by now why the title is in that way. Yes, my friend requested me to do a task. What is the request and how I completed that will be known to you if you read this story.

The Story

Two days back my friend Sai Madhu is leaving to his home place from our office in Kochi, which is 700 miles away. He booked the train and should leave in the afternoon. He is very passionate about cricket. He never missed the score when the Indian cricket team is playing. On the same day there is an ODI match between England and  India. Because he doesn’t have a smartphone to access, in the train, he is crippled  to know the score. But he had a feature phone. He requested me to send the score as sms frequently, and I gave my word. I have lots of work…

View original post 733 more words

Standard
Uncategorized

5 Simple Rules For Building Great Python Packages

A very good article on building great python packages.

Corps of Engineers

ryanlerch_Roundabout_SignA package seems simple enough to build, just a collection of modules in a directory with an __init__.py, right? As straight-forward as it may seem, with more and more modifications to your package over time, a poorly designed package will tend towards circular dependency problems, and may become non-portable and brittle.

Following these 5 simple design patterns will help you avoid these common pitfalls, and write packages that will live long and prosper.

1. __init__.py is Only for Imports

For a simple package, you might be tempted to throw utility methods, factories and exceptions into your __init__.py. Don’t.

A well-formed __init__.py serves one very important purpose: to import from sub-modules. Your __init__.py should look something like this:

# ORDER MATTERS HERE -- SOME MODULES ARE DEPENDANT ON OTHERS from exceptions import FSQError, FSQEnvError, FSQEncodeError,\ FSQTimeFmtError, FSQMalformedEntryError,\ FSQCoerceError, FSQEnqueueError, FSQConfigError,\ FSQPathError, FSQInstallError, FSQCannotLockError,\ FSQWorkItemError, FSQTTLExpiredError,\ FSQMaxTriesError, FSQScanError, FSQDownError,\ FSQDoneError, FSQFailError, FSQTriggerPullError,\ FSQHostsError, FSQReenqueueError…

View original post 1,190 more words

Standard
Uncategorized

A surprize for you

Hi there pythonistas. You might have noticed that I haven’t been active much on this blog. There’s a reason for that. I was preparing a PyCon talk. Yes I was really preparing a PyCon talk. The title of the talk is web scraping in python. I have submitted the proposal and now I am waiting for it’s acceptance. Do pray for it’s acceptance and after that you will be able to see me in Montreal next year 😉 . I will keep you updated with the status of my talk that whether it is accepted or not.

Standard
Uncategorized

Extracting pixel values of an image in python

This is a very nice post which teaches you some of the basics of PIL (python imaging library) . Make sure that you read it if you are interested in images.

Source Dexter

I wanted to extract  each pixel values  so that I can use them for  locating simple objects in an image. Every image is made up of pixels and when these values are extracted using python, four values are obtained for each pixel (R,G,B,A). This is called the ,G,B,A). This is called the RGBA colour space having the Red, Green, Blue colours and Alpha  value respectively. The Alpha values indicate thecolour space having the Red, Green, Blue colours and Alpha  value respectively. The Alpha values indicate the

The Alpha values indicate the transparency or the background factor in the image. a “.png” image, for example, can  be without a background and is said to be transparent.

In python, we use a library called PIL (python imaging Library). The modules in this library are used for image processing and has support for many file formats like png, jpg, bmp, gif etc. It…

View original post 344 more words

Standard
Uncategorized

Software Spotlight: Bitmessage

One of the latest application made with python. Definitely worth checking out. Do share your views in the comments below.

The Linux Cauldron

Bitmessage is one cool piece of software.  There are a lot of good things about it, but also a few pitfalls to watch out for.  In concept, Bitmessage is a P2P communications protocol in which you can send encrypted messages to others through special IDs or “subscribers.”  Being decentralized in nature, it is a much desired messaging system for those who do not wish to be identified.  Bitmessage is built on Python, enabling it to be cross-platform.

Authentication is strong and a paramount feature of the software, deterring spoof attacks and avoids storage of “non-content” data from the sender and receiver.  This includes identifying information that may finger either side.  In doing so, Bitmessage sidesteps eavsdroppers and wiretappers who are clawing at breadcrumbs for potential “threats.”

The one thing that is not quite there yet is an audit of the software itself.  Bitmessage carefully puts this disclaimer right on the…

View original post 376 more words

Standard