Tag Archives: python

Twitter Streaming API with Python

Hasin Vai has a good post about collecting tweets in real time with php. Here’s the post: http://hasin.wordpress.com/2009/06/20/collecting-data-from-streaming-api-in-twitter/ If you are a php developer look into there. Well, I am going to cover Python for the Twitter streaming API. You … Continue reading

Tagged , | 3 Comments

Python: Sending a bunch of images as email attachments

Python is just beautiful! In my last post I mentioned how you can setup an email server. Now, here’s the code I use to send a bunch of images as attachments with my outgoing emails. This code snippet was taken … Continue reading

Tagged , | 1 Comment

Python: Printing without newline or space :)

While coding in Python, I have seen that the Print statement adds a newline to it’s output which is very helpful in most cases. While I have to add a newline character manually in PHP, I have to type less … Continue reading

Tagged | 3 Comments

Handling Exceptions in PHP and Python

It’s really a very important programming practice to properly handle any possible exceptions… It makes the code more stable, efficient and re-usable. PHP: PHP now has a very good exception handling mechanism. Just put a “try” block and then “catch … Continue reading

Tagged , | 1 Comment

Why I like Python more than PHP ?

A friend of mine asked me a few days ago, why I like Python more than PHP given that I am more skilled in PHP than in Python. Well, here is the answer. I like Python because: – On my … Continue reading

Tagged , | 1 Comment

Calling a function using string

PHP: In php, you can assign a function name as a string to a variable and call the function by adding “()” after the variable name and appending a semicolon. Like this: function masnun($str) { echo "$str \n"; } $str … Continue reading

Tagged , | Leave a comment

Building Command Line Interface using Python

Creating a command line interface with Python is pretty easy Python has a built in module — “cmd” to assist you in building a command line interface of your application. In this example, I have created a dummy shell that … Continue reading

Tagged | 1 Comment

Open Source and Multilingual Eid Greetings from a Programmer :)

Wishing you all a very happy Eid Day PHP: <?php class Eid { function Mubarak() { echo __CLASS__." ".__FUNCTION__; } } $eid = new Eid; $eid->Mubarak(); ?> Python: #!/usr/bin/env python   import inspect   class Eid: def Mubarak(self): print self.__class__.__name__, … Continue reading

Tagged , | 3 Comments

HTML and XML Parsing in Python using BeautifulSoup :)

I have been looking for a good library in Python for handling HTML and XML. I knew about BeautifulSoup but never cared about it much. But this time, when I was looking for a way to scrape web sites and … Continue reading

Tagged | Leave a comment

Creating Dictonaries from Arrays / Lists

PHP: In PHP, we can create a new associative array or dictionary by using the array_combine() function. Just feed two arrays as the parameters to this function and you get back a dictionary. The first array elements are converted into … Continue reading

Tagged , | 1 Comment