<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1902979661984927761</id><updated>2012-02-01T23:50:29.267+06:00</updated><category term='pyhp'/><category term='python web spider'/><category term='lambda function'/><category term='random elements'/><category term='nohup'/><category term='Python video'/><category term='floating point number'/><category term='web crawler'/><category term='python http get'/><category term='google app engine.'/><category term='write large file'/><category term='cookie'/><category term='python localtime'/><category term='Plain Text'/><category term='csv read'/><category term='python list'/><category term='python unicode'/><category term='Python 2.5.2'/><category term='linux command'/><category term='python freelance work'/><category term='Python for Mobile Phone'/><category term='OOP in Python'/><category term='python urlparse'/><category term='facebook application'/><category term='Python Jobs'/><category term='facebook'/><category term='web spider'/><category term='get remote file size (http)'/><category term='prime number'/><category term='user agent'/><category term='python file'/><category term='swap integers'/><category term='python ebook'/><category term='python code'/><category term='regular expression'/><category term='programming contest'/><category term='Beautiful Soup'/><category term='random word'/><category term='HTML'/><category term='getch'/><category term='url redirect'/><category term='reduce image size'/><category term='python dictionary'/><category term='proxy'/><category term='ftp upload'/><category term='Python send email'/><category term='getacoder'/><category term='online judge'/><category term='postfix'/><category term='infix'/><category term='python web crawler'/><category term='random string'/><category term='swap values python'/><category term='design pattern'/><category term='Palindrome'/><category term='settimeout'/><category term='python'/><category term='CSV write in Python'/><category term='login script in python'/><category term='python command line argument'/><category term='Python Free eBook'/><category term='python list copy'/><category term='reverse polish notation'/><category term='fast python I/O'/><category term='python download file'/><category term='python hex to ASCII'/><category term='Python IDE'/><category term='urllib2'/><category term='linux'/><category term='python book'/><category term='read firefox cache'/><category term='twitter api'/><category term='basic http authentication'/><category term='python web frameworks'/><category term='round'/><category term='execute'/><category term='background process'/><category term='PyS60'/><category term='ASCII Code'/><category term='extract domain'/><category term='HTTP POST'/><category term='Python Image resize'/><category term='python hypertext preprocessor'/><category term='remove duplicate'/><category term='user-agent'/><category term='Python create thumbnail'/><category term='email address scraper'/><category term='python http post'/><category term='unix'/><category term='rentacoder'/><category term='code search'/><category term='HTTP Response Header'/><category term='Python reformat string data'/><category term='Leap Year'/><category term='python console input'/><category term='python version'/><category term='Python Database Programming'/><title type='text'>life is short - you need Python!</title><subtitle type='html'>A blog on Python with tutorials, code, programs, tips and tricks, how-to, book-list, crawler / spider help, data structure and algorithm implementation and many more ...</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default?start-index=101&amp;max-results=100'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>108</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-3201381174244036369</id><published>2011-12-01T02:32:00.000+06:00</published><updated>2011-12-01T02:32:18.673+06:00</updated><title type='text'>About Us Page Finder in Python</title><content type='html'>Few months ago, I wrote a Python code that tries to find the about us page given a URL. You can test it here: &lt;a href="http://208.43.85.103/cgi-bin/aboutus/main.py"&gt;http://208.43.85.103/cgi-bin/aboutus/main.py&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I have used some heuristics from my observation to write the code. But as I have started to learn machine learning (&lt;a href="http://www.ml-class.org"&gt;http://www.ml-class.org&lt;/a&gt;), I am thinking to apply machine learning technique and rewrite this. I shall try to do it later, may be last week of December. Before doing this, I would like to improve my current program by incorporating more logic (but no ml technique). I shall publish the current algorithm soon here, but first it would be great if you can test it and give me some feedback and suggestions.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-3201381174244036369?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/3201381174244036369/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=3201381174244036369' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3201381174244036369'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3201381174244036369'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2011/12/about-us-page-finder-in-python.html' title='About Us Page Finder in Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-5955102521442579645</id><published>2011-10-29T03:28:00.000+06:00</published><updated>2011-10-29T03:28:10.597+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python dictionary'/><category scheme='http://www.blogger.com/atom/ns#' term='python list'/><title type='text'>Pythonic way to convert a list into dictionary</title><content type='html'>Here is a simple Python code that converts a list into a dictionary.&lt;br /&gt;&lt;br /&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; def list_to_dict(li):  &lt;br /&gt;     dct = {}  &lt;br /&gt;     for item in li:  &lt;br /&gt;         if dct.has_key(item):  &lt;br /&gt;             dct[item] = dct[item] + 1  &lt;br /&gt;         else:  &lt;br /&gt;             dct[item] = 1  &lt;br /&gt;     return dct  &lt;br /&gt;&lt;br /&gt; li = [1, 1, 1, 2, 3, 3, 4, 4, 4, 4, 4, 5, 6, 7, 7]  &lt;br /&gt; print list_to_dict(li)  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Now I am looking for more Pythonic way to do this task. Any ideas?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-5955102521442579645?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/5955102521442579645/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=5955102521442579645' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/5955102521442579645'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/5955102521442579645'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2011/10/pythonic-way-to-convert-list-into.html' title='Pythonic way to convert a list into dictionary'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-3342603965675016454</id><published>2011-09-06T13:28:00.000+06:00</published><updated>2011-09-06T13:28:04.075+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='facebook'/><title type='text'>Facebook scripting in Python</title><content type='html'>I just came across &lt;a href="http://blog.carduner.net/2011/09/06/easy-facebook-scripting-in-python/"&gt;this blog&lt;/a&gt; that shows an easy way to play with facebook api using python. It is &lt;blockquote&gt;micro api client that implements the client-side authentication flow and has a few utility functions for accessing the graph api and fql.&lt;/blockquote&gt;&lt;br /&gt;But unfortunately I am getting error while trying with this code:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;from urllib import urlretrieve&lt;br /&gt;import imp&lt;br /&gt;urlretrieve('https://raw.github.com/gist/1194123/fbconsole.py', '.fbconsole.py')&lt;br /&gt;fb = imp.load_source('fb', '.fbconsole.py')&lt;br /&gt;&lt;br /&gt;fb.AUTH_SCOPE = ['stream_publish']&lt;br /&gt;fb.authenticate()&lt;br /&gt;&lt;br /&gt;status = fb.graph_post("/me/feed", {"message":"Hello this is from python"})&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-3342603965675016454?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/3342603965675016454/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=3342603965675016454' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3342603965675016454'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3342603965675016454'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2011/09/facebook-scripting-in-python.html' title='Facebook scripting in Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-4707129296214725716</id><published>2011-08-30T09:24:00.000+06:00</published><updated>2011-08-30T09:24:11.812+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python ebook'/><category scheme='http://www.blogger.com/atom/ns#' term='python book'/><title type='text'>Interactive Python Book</title><content type='html'>An &lt;a href="http://thinkcspy.appspot.com"&gt;online interactive edition&lt;/a&gt; of the book &lt;a href="http://greenteapress.com/thinkpython/"&gt;How to Think Like a Computer Scientist (by Elkner et. al)&lt;/a&gt; is being developed by Brad Miller and David Ranum. I think it is going to be a great online resource to learn python, specially for the beginners. Students can do homework right in the browser (yes, and that's why for this ebook you will require html5 supported modern browser). The site is developed using Google App Engine and you will need a gmail account to access the ebook. They used Python 3 instead of Python 2.x in the book, which is a good thing in my opinion. So you can check the book here: &lt;a href="http://thinkcspy.appspot.com"&gt;http://thinkcspy.appspot.com&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-4707129296214725716?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/4707129296214725716/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=4707129296214725716' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/4707129296214725716'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/4707129296214725716'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2011/08/interactive-python-book.html' title='Interactive Python Book'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-4432469740168045606</id><published>2011-08-21T14:44:00.000+06:00</published><updated>2011-08-21T14:44:27.442+06:00</updated><title type='text'>The Zen of Python</title><content type='html'>Well, if you are not sure about what I am talking, start the Python interpreter. Then &lt;code&gt;import this&lt;/code&gt;, press enter and read the output. :)&lt;br /&gt;&lt;code&gt;&lt;br /&gt;subeen@subeen-Satellite-L300:~$ python&lt;br /&gt;Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) &lt;br /&gt;[GCC 4.5.2] on linux2&lt;br /&gt;Type "help", "copyright", "credits" or "license" for more information.&lt;br /&gt;&gt;&gt;&gt; import this&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-4432469740168045606?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/4432469740168045606/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=4432469740168045606' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/4432469740168045606'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/4432469740168045606'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2011/08/zen-of-python.html' title='The Zen of Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-832909666167660271</id><published>2011-04-29T03:07:00.001+06:00</published><updated>2011-04-29T03:10:14.865+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Plain Text'/><category scheme='http://www.blogger.com/atom/ns#' term='regular expression'/><category scheme='http://www.blogger.com/atom/ns#' term='python'/><category scheme='http://www.blogger.com/atom/ns#' term='HTML'/><title type='text'>HTML to TEXT in Python</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I just wrote a small Python program. In the script there was a part where I needed to get the body of a web page and get rid of all the html tags, javascript, css styles, html comments etc. So I searched Google, found several threads in stackoverflow and then found this: &lt;a href="http://www.aaronsw.com/2002/html2text/"&gt;http://www.aaronsw.com/2002/html2text/&lt;/a&gt; This looks cool. But when I tested it against the 'about me' page of my blog, it didn't work because of some broken tags! Then I started to write the html to text function myself to get the plain text only. With help of regular expression I solved my problem (but may be I created more problems!). Here is my Python code:&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;def html_to_text(data):&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # remove the newlines&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data = data.replace("\n", " ")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data = data.replace("\r", " ")&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # replace consecutive spaces into a single one&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data = " ".join(data.split())&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # get only the body content&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; bodyPat = re.compile(r'&amp;lt; body[^&amp;lt;&amp;gt;]*?&amp;gt;(.*?)&amp;lt; / body &amp;gt;', re.I)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = re.findall(bodyPat, data)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data = result[0]&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # now remove the java script&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; p = re.compile(r'&amp;lt; script[^&amp;lt;&amp;gt;]*?&amp;gt;.*?&amp;lt; / script &amp;gt;')&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data = p.sub('', data)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # remove the css styles&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; p = re.compile(r'&amp;lt; style[^&amp;lt;&amp;gt;]*?&amp;gt;.*?&amp;lt; / style &amp;gt;')&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data = p.sub('', data)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # remove html comments&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; p = re.compile(r'')&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data = p.sub('', data)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # remove all the tags&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; p = re.compile(r'&amp;lt;[^&amp;lt;]*?&amp;gt;')&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data = p.sub('', data)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return data&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Note that in order to use&amp;nbsp; the function, you need to remove some space characters, just copy-paste won't work. Guess why. ;)&lt;br /&gt;&lt;br /&gt;Please share if you have better ideas or know useful libraries that can perform better than my code. Don't forget to test it first! :)&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-832909666167660271?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/832909666167660271/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=832909666167660271' title='10 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/832909666167660271'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/832909666167660271'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2011/04/html-to-text-in-python.html' title='HTML to TEXT in Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>10</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-4407889245473364171</id><published>2011-04-16T02:50:00.001+06:00</published><updated>2011-04-16T02:52:53.067+06:00</updated><title type='text'>Replace consecutive whitespace with a single space</title><content type='html'>Sometimes we need to replace consecutive whitespace in a string  with a single space. This is a good practice while parsing html files. Let me show you two ways of doing this.&lt;br /&gt;&lt;br /&gt;First one is to split the string and join. Here is the code snippet:&lt;br /&gt;&lt;code&gt;&gt;&gt;&gt; s = "a      b       c d             e f"&lt;br /&gt;&gt;&gt;&gt; " ".join(s.split())&lt;br /&gt;'a b c d e f'&lt;/code&gt;&lt;br /&gt;You can check more string methods here: &lt;a href="http://docs.python.org/release/2.5.2/lib/string-methods.html"&gt;http://docs.python.org/release/2.5.2/lib/string-methods.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Second method is to use regular expression. Here is the code:&lt;br /&gt;&lt;code&gt;&gt;&gt;&gt; import re&lt;br /&gt;&gt;&gt;&gt; s = "a      b       c d             e f"&lt;br /&gt;&gt;&gt;&gt; p = re.compile(r'\s+')&lt;br /&gt;&gt;&gt;&gt; data = p.sub(' ', s)&lt;br /&gt;&gt;&gt;&gt; data&lt;br /&gt;'a b c d e f'&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-4407889245473364171?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/4407889245473364171/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=4407889245473364171' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/4407889245473364171'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/4407889245473364171'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2011/04/replace-consecutive-whitespace-with.html' title='Replace consecutive whitespace with a single space'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-6605805612468650890</id><published>2011-04-03T23:17:00.000+06:00</published><updated>2011-04-03T23:17:38.549+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='google app engine.'/><category scheme='http://www.blogger.com/atom/ns#' term='facebook application'/><title type='text'>Create Facebook Application in Python using App Engine</title><content type='html'>So far I have used PHP for all the facebook applications that I (and my other team members) have developed. Today I was thinking about using Python to develop a facebook app. After Google search I found some links and at the same time I asked one of my ex-colleagues whether he used Python for any facebook application (as I knew that he was exploring Google App Engine and also Facebook app development). Then he told me that there is already a sample application in facebook that uses Python and most interestingly Google app engine! The application is named '&lt;a href="https://developers.facebook.com/docs/samples/canvas/"&gt;Run With Friends&lt;/a&gt;'. Though I have seen this page before but never looked at it closely. So, I think this page is the right place to get started creating facebook app in Python and GAE: &lt;a href="https://developers.facebook.com/docs/samples/canvas/"&gt;https://developers.facebook.com/docs/samples/canvas/&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The project I am planning to do might take 4 to 6 months (if I get regular free time). Let me know if you have already done any interesting facebook app using Google app engine.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-6605805612468650890?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/6605805612468650890/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=6605805612468650890' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6605805612468650890'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6605805612468650890'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2011/04/create-facebook-application-in-python.html' title='Create Facebook Application in Python using App Engine'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-3486849189626664306</id><published>2010-11-28T01:11:00.000+06:00</published><updated>2010-11-28T01:11:22.906+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='fast python I/O'/><title type='text'>fast way to get input from stdin - Python</title><content type='html'>I am looking for faster way for taking input from stdin in Python. So far I found three methods. input() - which is suitable for integers, raw_input() - reads the input as string and another one is sys.stdin.readline(). So far I have found sys.stdin.readline() is the fastest. Do you have any idea to read input (from console) in Python which is faster?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-3486849189626664306?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/3486849189626664306/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=3486849189626664306' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3486849189626664306'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3486849189626664306'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2010/11/fast-way-to-get-input-from-stdin-python.html' title='fast way to get input from stdin - Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-8564072299860080613</id><published>2010-11-25T06:16:00.001+06:00</published><updated>2010-11-25T06:56:05.359+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Palindrome'/><category scheme='http://www.blogger.com/atom/ns#' term='python'/><title type='text'>Python program to find the next palindrome</title><content type='html'>Yesterday I wrote a Python program to find the next palindrome to solve &lt;a href="https://www.spoj.pl/problems/PALIN/"&gt;this problem from SPOJ&lt;/a&gt;. My first accepted solution took four seconds to run. Today I improved the code and now it takes 1.13 seconds. In the rank-list I found people solving this problem with Python program that finishes execution in less than half seconds. Wondering whether I am missing any trick or not using Python properly. :-S&lt;br /&gt;&lt;br /&gt;The problem is simple. &lt;blockquote&gt;A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. For a given positive integer K of not more than 1000000 digits, write the value of the smallest palindrome larger than K to output. Numbers are always displayed without leading zeros.&lt;/blockquote&gt;&lt;br /&gt;As the number can be as large as 1000000 digits, stupid solutions won't finish it's execution in time (thus will get 'Time Limit Exceeded').&lt;br /&gt;&lt;br /&gt;I am not going to explain my logic in detail, as I don't want to deprive you of the fun of solving problem. What I basically did was to divide the number into two parts, did some comparison between the corresponding characters (digits) and applied some logics. As soon as I realize that there is some change which made the number larger than it was, I get out of the loop. I don't make any change to the second part of the string, as it's a palindrome, I can generate it from the first part.&lt;br /&gt;&lt;br /&gt;If you want to solve the problem, don't forget to test your program using the following numbers:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;0&lt;br /&gt;9&lt;br /&gt;808&lt;br /&gt;2133&lt;br /&gt;199&lt;br /&gt;1999&lt;br /&gt;319887788993&lt;br /&gt;333321&lt;br /&gt;111&lt;br /&gt;1111&lt;br /&gt;999&lt;br /&gt;9999&lt;br /&gt;99999&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Here is my code:&lt;br /&gt;&lt;pre&gt;def palin(s):        &lt;br /&gt;    word_len = len(s)&lt;br /&gt;    if word_len == 1:&lt;br /&gt;        if s == "9":&lt;br /&gt;            return "11"&lt;br /&gt;        else:&lt;br /&gt;            return str(int(s)+1)                &lt;br /&gt;    &lt;br /&gt;    if word_len % 2 == 0:        &lt;br /&gt;        m = ''&lt;br /&gt;    else:         &lt;br /&gt;        m = s[word_len/2]&lt;br /&gt;    &lt;br /&gt;    h1 = (word_len / 2) - 1           &lt;br /&gt;    h2 = (word_len + 1) / 2&lt;br /&gt;    &lt;br /&gt;    i = h1&lt;br /&gt;    j = h2&lt;br /&gt;    &lt;br /&gt;    if m:    &lt;br /&gt;        while s[i] == s[j]:&lt;br /&gt;            i -= 1&lt;br /&gt;            j += 1&lt;br /&gt;            if i &lt; 0: break&lt;br /&gt;        &lt;br /&gt;        if i &lt; 0 or s[i] &lt; s[j]:&lt;br /&gt;            if m == '9':&lt;br /&gt;                m = "0"&lt;br /&gt;            else:&lt;br /&gt;                m = str(int(m) + 1)&lt;br /&gt;                return s[:h1+1] + m + s[h1::-1]&lt;br /&gt;                    &lt;br /&gt;    &lt;br /&gt;    while i &gt;= 0:&lt;br /&gt;        if s[i] &gt; s[j]:&lt;br /&gt;            break&lt;br /&gt;        elif s[i] &lt; s[j]:            &lt;br /&gt;            s = s[:i] + str(int(s[i]) + 1) + "0" * h1              &lt;br /&gt;            break&lt;br /&gt;        elif i &gt; 0: &lt;br /&gt;            k = i - 1&lt;br /&gt;            l = j + 1&lt;br /&gt;            while s[k] == s[l]:&lt;br /&gt;                k -= 1&lt;br /&gt;                l += 1&lt;br /&gt;                if k &lt; 0: break&lt;br /&gt;            if k &gt;= 0:&lt;br /&gt;                if s[k] &lt; s[l]:&lt;br /&gt;                    if s[i] == '9':&lt;br /&gt;                        s = s[:i] + '0' + s[i+1:]&lt;br /&gt;                    else:&lt;br /&gt;                        x = str(int(s[i]) + 1)&lt;br /&gt;                        s = s[:i] + x + s[i+1:]&lt;br /&gt;                        break&lt;br /&gt;                i = k + 1&lt;br /&gt;                j = l - 1&lt;br /&gt;            else:&lt;br /&gt;                if s[i] == '9':&lt;br /&gt;                    s = s[:i] + '0' + s[i+1:]                    &lt;br /&gt;                else:&lt;br /&gt;                    x = str(int(s[i]) + 1)&lt;br /&gt;                    s = s[:i] + x + s[i+1:]                    &lt;br /&gt;                    break&lt;br /&gt;        &lt;br /&gt;        else:&lt;br /&gt;            if s[i] == '9':&lt;br /&gt;                s = s[:i] + '1' + s[i+1:]&lt;br /&gt;                m += '0'                &lt;br /&gt;                break            &lt;br /&gt;                                &lt;br /&gt;        i -= 1&lt;br /&gt;        j += 1&lt;br /&gt;                &lt;br /&gt;    &lt;br /&gt;    return s[:h1+1] + m + s[h1::-1]&lt;br /&gt;    &lt;br /&gt;t = int(raw_input())&lt;br /&gt;&lt;br /&gt;while t:&lt;br /&gt;    t -= 1&lt;br /&gt;    s = raw_input()        &lt;br /&gt;    print palin(s)&lt;br /&gt;&lt;/pre&gt;Let me know if you can come up with faster and / or more Pythonic solution.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-8564072299860080613?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/8564072299860080613/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=8564072299860080613' title='15 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/8564072299860080613'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/8564072299860080613'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2010/11/python-program-to-find-next-palindrome.html' title='Python program to find the next palindrome'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>15</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-524467453584861905</id><published>2010-11-24T00:00:00.000+06:00</published><updated>2010-11-24T00:00:09.849+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='reverse polish notation'/><category scheme='http://www.blogger.com/atom/ns#' term='infix'/><category scheme='http://www.blogger.com/atom/ns#' term='postfix'/><title type='text'>Simple Infix to Postfix in Python</title><content type='html'>Today I wrote a Python program to transform an expression to reverse polish notation in order to solve the problem &lt;a href="http://www.spoj.pl/problems/ONP/"&gt;Transform the Expression&lt;/a&gt; and it worked fine. Here is my code:&lt;br /&gt;&lt;pre&gt;def rpn(s):&lt;br /&gt;    var_list = []&lt;br /&gt;    symb_list = []&lt;br /&gt;    for c in s:&lt;br /&gt;        if c &gt;= 'a' and c &lt;= 'z':&lt;br /&gt;            var_list.append(c)&lt;br /&gt;        elif c in ['^', '*', '/', '+', '-']:&lt;br /&gt;            symb_list.append(c)&lt;br /&gt;        elif c == ')':&lt;br /&gt;            x = var_list.pop()&lt;br /&gt;            y = var_list.pop()&lt;br /&gt;            z = symb_list.pop()&lt;br /&gt;            var_list.append(y + x + z)&lt;br /&gt;        #print var_list, symb_list&lt;br /&gt;        &lt;br /&gt;    return var_list[0]&lt;br /&gt;        &lt;br /&gt;t = int(raw_input())&lt;br /&gt;&lt;br /&gt;while t:&lt;br /&gt;    t -= 1&lt;br /&gt;    s = raw_input()        &lt;br /&gt;    print rpn(s)&lt;br /&gt;&lt;/pre&gt;The algorithm is very simple which you should be able to follow if you study my code. You can uncomment the line &lt;code&gt;#print var_list, symb_list&lt;/code&gt; to see a simulation. Note that the Python program I wrote is not the perfect infix to postfix converter but it worked for the problem. The ideal program should work without taking the advantage of brackets. :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-524467453584861905?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/524467453584861905/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=524467453584861905' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/524467453584861905'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/524467453584861905'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2010/11/simple-infix-to-postfix-in-python.html' title='Simple Infix to Postfix in Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-6228291570589992464</id><published>2010-11-23T00:30:00.004+06:00</published><updated>2010-11-23T03:36:57.425+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='prime number'/><category scheme='http://www.blogger.com/atom/ns#' term='python code'/><title type='text'>Prime Number Generator in Python using Sieve Method</title><content type='html'>I have implemented a prime number generator in Python using &lt;a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes"&gt;Sieve of Eratosthenes&lt;/a&gt;. Here is my code:&lt;br /&gt;&lt;pre&gt;import math&lt;br /&gt;&lt;br /&gt;high = 10000&lt;br /&gt;root = int(math.sqrt(high) + 1.0)&lt;br /&gt;&lt;br /&gt;ara = [x % 2 for x in xrange(0, high)]&lt;br /&gt;&lt;br /&gt;ara[1] = 0&lt;br /&gt;ara[2] = 1&lt;br /&gt;&lt;br /&gt;x = 3&lt;br /&gt;while x &lt;= root:        &lt;br /&gt;    if ara[x]:&lt;br /&gt;        z = x * x&lt;br /&gt;        while z &lt; high:             &lt;br /&gt;            ara[z] = 0&lt;br /&gt;            z += (x + x)        &lt;br /&gt;    x += 2&lt;br /&gt;        &lt;br /&gt;prime = [x for x in xrange(2, len(ara)) if ara[x] == 1]&lt;br /&gt;print prime&lt;br /&gt;&lt;/pre&gt;I am looking for ideas to make my code faster. I tested my Python program using the code for solving a problem named &lt;a href="https://www.spoj.pl/problems/PRIME1/"&gt;Prime Generator in SPOJ&lt;/a&gt;. I could solve the problem correctly that took 3 seconds time and 3.8 MB memory.I am posting another code I found &lt;a href="http://code.activestate.com/recipes/366178-a-fast-prime-number-list-generator/"&gt;here&lt;/a&gt;. This one is similar implementation to mine but more Pythonic and much faster:&lt;pre&gt;nroot = int(math.sqrt(n))&lt;br /&gt;sieve = [True] * (n+1)&lt;br /&gt;sieve[0] = False&lt;br /&gt;sieve[1] = False&lt;br /&gt;&lt;br /&gt;for i in xrange(2, nroot+1):&lt;br /&gt;    if sieve[i]:&lt;br /&gt;        m = n/i - i&lt;br /&gt;        sieve[i*i: n+1:i] = [False] * (m+1)&lt;br /&gt;&lt;br /&gt;sieve = [i for i in xrange(n+1) if sieve[i]]&lt;br /&gt;&lt;/pre&gt;I updated the above code and now it's 20% faster! :)&lt;pre&gt;nroot = int(math.sqrt(n))&lt;br /&gt;sieve = [True] * (n+1)&lt;br /&gt;sieve[0] = False&lt;br /&gt;sieve[1] = False&lt;br /&gt;sieve[4: n+1:2] = [False] * (n / 2 - 1)&lt;br /&gt;for i in xrange(2, nroot+1):&lt;br /&gt;    if sieve[i]:&lt;br /&gt;        m = (n/i - i) / 2&lt;br /&gt;        sieve[i*i: n+1:i+i] = [False] * (m+1)&lt;br /&gt;&lt;br /&gt;sieve = [i for i in xrange(n+1) if sieve[i]]&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-6228291570589992464?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/6228291570589992464/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=6228291570589992464' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6228291570589992464'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6228291570589992464'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2010/11/prime-number-generator-in-python-using.html' title='Prime Number Generator in Python using Sieve Method'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-8000557287859033803</id><published>2010-11-05T18:59:00.000+06:00</published><updated>2010-11-05T18:59:29.348+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python video'/><category scheme='http://www.blogger.com/atom/ns#' term='python'/><title type='text'>Teach Yourself Python using Google's Python class</title><content type='html'>Recently I found an interesting video and later found &lt;a href="http://code.google.com/edu/languages/google-python-class/index.html"&gt;this&lt;/a&gt;! It's a collection of well thought-out tutorials and videos with exercises (right now not very useful for me though :p). It's done under Google Edu project. I have checked couple of videos and looked at the exercises. I think it's a very good resource for someone who wants to learn Python. So, if you are a python beginner you will find &lt;a href="http://code.google.com/edu/languages/google-python-class/index.html"&gt;Google's Python Class&lt;/a&gt; useful, but if you already know these basic Python stuffs, what you can do is to share so that another Python newbie can get help. :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-8000557287859033803?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/8000557287859033803/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=8000557287859033803' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/8000557287859033803'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/8000557287859033803'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2010/11/teach-yourself-python-using-googles.html' title='Teach Yourself Python using Google&apos;s Python class'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-1279690562336486094</id><published>2010-10-28T06:18:00.000+06:00</published><updated>2010-10-28T06:18:14.783+06:00</updated><title type='text'>Facebook like button Added</title><content type='html'>Just added facebook like button in my blog. It was simple. First I Googled using the term 'add facebook like in blogspot'. Then got this link: &lt;a href="http://www.wikihow.com/Add-Facebook-Like-to-Blogger"&gt;http://www.wikihow.com/Add-Facebook-Like-to-Blogger&lt;/a&gt; and followed the instructions. But I got an error while changing the html source. &lt;code&gt;XML error message: The reference to entity "layout" must end with the ';' delimiter.&lt;/code&gt;. I needed to replace the &amp;layout with &amp; amp;layout (you need to delete the space). That's all.&lt;br /&gt;&lt;br /&gt;Now you can Like my posts. ;)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-1279690562336486094?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/1279690562336486094/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=1279690562336486094' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/1279690562336486094'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/1279690562336486094'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2010/10/facebook-like-button-added.html' title='Facebook like button Added'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-2575703433455177849</id><published>2010-09-30T12:53:00.000+06:00</published><updated>2010-09-30T12:56:41.965+06:00</updated><title type='text'>Python code to generate dates in a range</title><content type='html'>Today I needed to write a Python script where a part of it was to generate all dates in a range. I am sharing a simplified version of my code.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import datetime&lt;br /&gt;&lt;br /&gt;def generate_dates(start_date, end_date):&lt;br /&gt;    td = datetime.timedelta(hours=24)&lt;br /&gt;    current_date = start_date&lt;br /&gt;    while current_date &lt;= end_date:&lt;br /&gt;        print current_date&lt;br /&gt;        current_date += td&lt;br /&gt;&lt;br /&gt;start_date = datetime.date(2010, 1, 25)&lt;br /&gt;end_date = datetime.date(2010, 3, 5)&lt;br /&gt;generate_dates(start_date, end_date)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As always, please share if you know other methods that serve the purpose.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-2575703433455177849?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/2575703433455177849/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=2575703433455177849' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2575703433455177849'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2575703433455177849'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2010/09/python-code-to-generate-dates-in-range.html' title='Python code to generate dates in a range'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-6630253375704958627</id><published>2010-09-27T08:32:00.000+06:00</published><updated>2010-09-27T08:39:23.268+06:00</updated><title type='text'>Insert an item to a tuple in Python</title><content type='html'>&lt;blockquote&gt;Tuples, like strings, are immutable: it is not possible to assign to the individual items of a tuple ...&lt;/blockquote&gt; [from python doc]. &lt;br /&gt;&lt;br /&gt;Say you create a tuple t:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; t = 1, 2, 3&lt;br /&gt;&gt;&gt;&gt; t&lt;br /&gt;(1, 2, 3)&lt;br /&gt;&gt;&gt;&gt; &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Now you need to assign value 4 to the 4th element of the tuple:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; t[3] = 4&lt;br /&gt;Traceback (most recent call last):&lt;br /&gt;  File "&lt;stdin&gt;", line 1, in &lt;module&gt;&lt;br /&gt;TypeError: 'tuple' object does not support item assignment&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Now you try append like a list:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; t.append(4)&lt;br /&gt;Traceback (most recent call last):&lt;br /&gt;  File "&lt;stdin&gt;", line 1, in &lt;module&gt;&lt;br /&gt;AttributeError: 'tuple' object has no attribute 'append'&lt;br /&gt;&gt;&gt;&gt; &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;No luck yet. So better covert the tuple to a list:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; l = list(t)&lt;br /&gt;&gt;&gt;&gt; l&lt;br /&gt;[1, 2, 3]&lt;br /&gt;&gt;&gt;&gt; l.append(4)&lt;br /&gt;&gt;&gt;&gt; l&lt;br /&gt;[1, 2, 3, 4]&lt;br /&gt;&gt;&gt;&gt; &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;And now convert the list to a tuple:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; t = tuple(l)&lt;br /&gt;&gt;&gt;&gt; t&lt;br /&gt;(1, 2, 3, 4)&lt;br /&gt;&gt;&gt;&gt; &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Do you know of more ways to do this?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-6630253375704958627?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/6630253375704958627/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=6630253375704958627' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6630253375704958627'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6630253375704958627'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2010/09/insert-item-to-tuple-in-python.html' title='Insert an item to a tuple in Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-3059544972860345612</id><published>2010-09-04T03:09:00.000+06:00</published><updated>2010-09-04T03:34:02.255+06:00</updated><title type='text'>Create child process in Python - Subprocess module</title><content type='html'>Recently in one of my projects I had to create subprocess (child process) in Python. Actually I had to run multiple instances and didn't want to wait till those processes finish their job. I used the &lt;a href="http://docs.python.org/library/subprocess.html"&gt;subprocess module&lt;/a&gt; to create those process. I am not sharing my actual code rather giving some sample code here that I wrote to understand the use of subprocess module myself which show you how to create child process (for which parent process need not wait for all the child processes to finish execution) using subprocess module.&lt;br /&gt;&lt;br /&gt;1. create a file named test.py&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;#!/usr/bin/env python&lt;br /&gt;&lt;br /&gt;import os, subprocess&lt;br /&gt;&lt;br /&gt;print "hello"&lt;br /&gt;&lt;br /&gt;urlList = ["http://python.org",&lt;br /&gt;"http://muktosoft.com",&lt;br /&gt;"http://bdosn.org",&lt;br /&gt;"http://matholympiad.org.bd",&lt;br /&gt;"http://bbc.co.uk",&lt;br /&gt;"http://cricinfo.com", &lt;br /&gt;"http://bdpy.org"]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;for url in urlList:&lt;br /&gt;    subprocess.Popen(["python", "test2.py", url])&lt;br /&gt;&lt;br /&gt;print "good bye\n"&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;2. now create another file in the same directory named test2.py.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import urllib2&lt;br /&gt;import sys&lt;br /&gt;from urlparse import urlparse&lt;br /&gt;&lt;br /&gt;url = sys.argv[1]&lt;br /&gt;&lt;br /&gt;print "\nURL: ", url&lt;br /&gt;&lt;br /&gt;usock = urllib2.urlopen(url)&lt;br /&gt;data = usock.read()&lt;br /&gt;usock.close()&lt;br /&gt;&lt;br /&gt;filename = urlparse(url).netloc + ".html"&lt;br /&gt;fp = open(filename, "w")&lt;br /&gt;fp.write(data)&lt;br /&gt;fp.close()&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now run the program test.py. &lt;br /&gt;&lt;br /&gt;test.py program doesn't wait for all the child processes to be finished. It just starts those and terminated. Each child process is terminated when they finish execution. Don't forget to notice the order in which html files are created in your directory. :)&lt;br /&gt;&lt;br /&gt;You might need to make the test2.py executable (chmod +x test2.py) but I am not sure whether it was necessary.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-3059544972860345612?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/3059544972860345612/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=3059544972860345612' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3059544972860345612'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3059544972860345612'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2010/09/create-child-process-in-python.html' title='Create child process in Python - Subprocess module'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-9188010026200764787</id><published>2010-09-03T00:19:00.000+06:00</published><updated>2010-09-03T07:52:55.595+06:00</updated><title type='text'>python code to retrive links from web page</title><content type='html'>There are several ways to extract / retrieve links (URL) from web page using Python. Let me discuss few ways.&lt;br /&gt;&lt;br /&gt;1. Using Beautiful Soup.&lt;br /&gt;You can find code to retrieve links from web page using beautiful soup in it's &lt;a href="http://www.crummy.com/software/BeautifulSoup/documentation.html"&gt;documentation&lt;/a&gt;.&lt;br /&gt;The code is simple:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import BeautifulSoup&lt;br /&gt;import urllib2&lt;br /&gt;&lt;br /&gt;print "Enter the URL: "&lt;br /&gt;url = raw_input("&amp;gt; ")&lt;br /&gt;usock = urllib2.urlopen(url)&lt;br /&gt;soup = BeautifulSoup.BeautifulSoup(html_source)&lt;br /&gt;links = BeautifulSoup.SoupStrainer('a')&lt;br /&gt;for link in BeautifulSoup.BeautifulSoup(response, parseOnlyThese=links): &lt;br /&gt; if link.has_key('href'):&lt;br /&gt;     print link['href']&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;2. I saw another code in the book &lt;a href="http://diveintopython.org/"&gt;dive into python&lt;/a&gt; that uses a html parser to extract url.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;from sgmllib import SGMLParser&lt;br /&gt;&lt;br /&gt;class URLLister(SGMLParser):&lt;br /&gt; def reset(self):&lt;br /&gt;     SGMLParser.reset(self)&lt;br /&gt;     self.urls = []   &lt;br /&gt;&lt;br /&gt; def start_a(self, attrs):&lt;br /&gt;     href = [v for k, v in attrs if k=='href']&lt;br /&gt;     if href:&lt;br /&gt;         self.urls.extend(href)&lt;br /&gt;&lt;br /&gt;if __name__ == "__main__":&lt;br /&gt; import urllib2&lt;br /&gt; print "Enter the URL: "&lt;br /&gt; url = raw_input("&amp;gt; ")&lt;br /&gt;&lt;br /&gt; usock = urllib2.urlopen(url) &lt;br /&gt; parser = URLLister() &lt;br /&gt; parser.feed(usock.read()) &lt;br /&gt; parser.close()&lt;br /&gt; usock.close()&lt;br /&gt;&lt;br /&gt; for url in parser.urls:&lt;br /&gt;     print url&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now try this URL for the above two programs: http://www.vworker.com&lt;br /&gt;For the first one you will get few links (not all) and for the second one you will get an error message. :(&lt;br /&gt;The reason is, there is an incorrect tag in the html source code (search the source code with the term 'strong')&lt;br /&gt;&lt;br /&gt;3. So I had to write this python script using regular expression.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import re&lt;br /&gt;import urllib2&lt;br /&gt;&lt;br /&gt;def get_hyperlinks(url, source): &lt;br /&gt; if url.endswith("/"):&lt;br /&gt;     url = url[:-1]&lt;br /&gt;&lt;br /&gt; urlPat = re.compile(r'&amp;lt;a [^&amp;lt;&amp;gt;]*?href=("|\')([^&amp;lt;&amp;gt;"\']*?)("|\')')&lt;br /&gt;&lt;br /&gt; result = re.findall(urlPat, source)&lt;br /&gt;&lt;br /&gt; urlList = []&lt;br /&gt;&lt;br /&gt; for item in result:&lt;br /&gt;     link = item[1]     &lt;br /&gt;     if link.startswith("http://") and link.startswith(url):&lt;br /&gt;         if link not in urlList:&lt;br /&gt;             urlList.append(link)&lt;br /&gt;     elif link.startswith("/"):&lt;br /&gt;         link = url + link&lt;br /&gt;         if link not in urlList:&lt;br /&gt;             urlList.append(link)&lt;br /&gt;     else:&lt;br /&gt;         link = url + "/" + link&lt;br /&gt;         if link not in urlList:&lt;br /&gt;             urlList.append(link)&lt;br /&gt; &lt;br /&gt; return urlList&lt;br /&gt;&lt;br /&gt;print "Enter the URL: "&lt;br /&gt;url = raw_input("&amp;gt; ")&lt;br /&gt;usock = urllib2.urlopen(url)&lt;br /&gt;data = usock.read()&lt;br /&gt;usock.close()&lt;br /&gt;print get_hyperlinks(url, data)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This code also takes care that there is no duplicate links. Now test this with http://www.vworker.com :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-9188010026200764787?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/9188010026200764787/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=9188010026200764787' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/9188010026200764787'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/9188010026200764787'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2010/09/python-code-to-retrive-links-from-web.html' title='python code to retrive links from web page'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-3672724658800903984</id><published>2010-08-26T04:57:00.000+06:00</published><updated>2010-08-26T05:16:50.443+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python Database Programming'/><title type='text'>Prevent sql injection in python using cursor.execute correctly</title><content type='html'>Today I did some searching about how to prevent sql injection while using Python and MySQLdb. Then I found some links with tips and also did some experiment and found something interesting.&lt;br /&gt;&lt;br /&gt;Usually I used to write mysql query in python this way:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;query = ".."&lt;br /&gt;cursor.execute(query)&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;But it can't prevent sql injection. Check this example: (It will be better if you create a table named user_info with the fields: id, name, email and populate the table with some data.)&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import MySQLdb&lt;br /&gt;&lt;br /&gt;try:&lt;br /&gt;    conn = MySQLdb.connect (host = "localhost",&lt;br /&gt;    user = "uname",&lt;br /&gt;    passwd = "pass",&lt;br /&gt;    db = "mydb")&lt;br /&gt;    cursor = conn.cursor()&lt;br /&gt;    &lt;br /&gt;    email = "' OR '1'='1"&lt;br /&gt;    query = "SELECT * FROM user_info WHERE email = '" + email + "'"&lt;br /&gt;    print query&lt;br /&gt;    cursor.execute(query)&lt;br /&gt;    &lt;br /&gt;    if cursor.rowcount &gt; 0:&lt;br /&gt;        print cursor.fetchall()&lt;br /&gt;    else:&lt;br /&gt;        print "no item found"&lt;br /&gt;        &lt;br /&gt;except MySQLdb.Error, e:&lt;br /&gt;    print "Error %d: %s" % (e.args[0], e.args[1])&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;It will show all records from user_info table! Because the query &lt;code&gt;SELECT * FROM user_info WHERE email = '' OR '1'='1'&lt;/code&gt; gets executed.&lt;br /&gt;&lt;br /&gt;Now if you run the following code this won't happen:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import MySQLdb&lt;br /&gt;&lt;br /&gt;try:&lt;br /&gt;    conn = MySQLdb.connect (host = "localhost",&lt;br /&gt;    user = "uname",&lt;br /&gt;    passwd = "pass",&lt;br /&gt;    db = "mydb")&lt;br /&gt;    cursor = conn.cursor()&lt;br /&gt;&lt;br /&gt;    email = "' OR '1'='1"&lt;br /&gt;    &lt;br /&gt;    cursor.execute("SELECT * FROM user_info WHERE email = %s", email)&lt;br /&gt;    &lt;br /&gt;    if cursor.rowcount &gt; 0:&lt;br /&gt;        print cursor.fetchall()&lt;br /&gt;    else:&lt;br /&gt;        print "no item found"&lt;br /&gt;        &lt;br /&gt;except MySQLdb.Error, e:&lt;br /&gt;    print "Error %d: %s" % (e.args[0], e.args[1])&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;It displays "no item found". It is secured as it lets the MySQLdb library to handle the necessary checking. Here is the format:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;cursor.execute("... %s ...%s", (param1, param2))&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Do you have any more suggestion to prevent sql injection while coding in Python thus improving security?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-3672724658800903984?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/3672724658800903984/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=3672724658800903984' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3672724658800903984'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3672724658800903984'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2010/08/prevent-sql-injection-in-python-using.html' title='Prevent sql injection in python using cursor.execute correctly'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-8702774230278131412</id><published>2010-07-17T19:43:00.000+06:00</published><updated>2010-07-17T19:49:00.866+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python IDE'/><title type='text'>Using Eclipse for Python with Pydev</title><content type='html'>So far I have been using gedit in my Ubuntu machine for Python coding. And I am very happy with it. :) But next week I am going to start another Python project (using Django) and I have decided to use Eclipse as the IDE. I have heard good things about it. So just installed pydev in Eclipse. Let me share some helpful links.&lt;br /&gt;&lt;br /&gt;1. &lt;a href="http://marketplace.eclipse.org/content/pydev-python-ide-eclipse"&gt;Pydev in Eclipse market place&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;2. &lt;a href="http://www.rose-hulman.edu/class/csse/resources/Eclipse/eclipse-python-configuration.htm"&gt;Step by step solution for configuring Eclipse for Python&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;3. &lt;a href="http://pydev.org/"&gt;Pydev home page&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Hope you will find this post useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-8702774230278131412?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/8702774230278131412/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=8702774230278131412' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/8702774230278131412'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/8702774230278131412'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2010/07/using-eclipse-for-python-with-pydev.html' title='Using Eclipse for Python with Pydev'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-2133537342103403828</id><published>2010-06-27T01:25:00.000+06:00</published><updated>2010-06-27T01:30:25.232+06:00</updated><title type='text'>Python for Kids</title><content type='html'>I am volunteering in a pilot project that targets to teach programming to school kids (class VIII-IX). My responsibility is to design the course. I have been researching about this and decided to use Python (not because it's my favorite language but because I think teaching Python would be a good idea).&lt;br /&gt;&lt;br /&gt;If anybody can share any useful resource, links or suggestions it will be highly appreciated.&lt;br /&gt;&lt;br /&gt;I shall keep you updated about the outcome of the project.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-2133537342103403828?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/2133537342103403828/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=2133537342103403828' title='14 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2133537342103403828'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2133537342103403828'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2010/06/python-for-kids.html' title='Python for Kids'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>14</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-7631622651103907418</id><published>2010-04-21T16:10:00.000+06:00</published><updated>2010-04-21T16:14:26.216+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='design pattern'/><title type='text'>Design Pattern in Python</title><content type='html'>I am exploring some design patters in Python and found some links that might be helpful for you to learn design pattern in Python. Though most of the design patterns are not language specific, but it's nice to see the examples in Python! :)&lt;br /&gt;&lt;br /&gt;Check the links:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.suttoncourtenay.org.uk/duncan/accu/pythonpatterns.html"&gt;Patterns in Python&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.python.org/workshops/1997-10/proceedings/savikko.html"&gt;Design Patterns in Python&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.aleax.it/gdd_pydp.pdf"&gt;Design Patterns in Python (presentation by Alex Martelli)&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.youtube.com/watch?v=0vJJlVBVTFg"&gt;Video on youtube!&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;Please share if you know about any useful resource / link related to design pattern in Python.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-7631622651103907418?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/7631622651103907418/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=7631622651103907418' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/7631622651103907418'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/7631622651103907418'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2010/04/design-pattern-in-python.html' title='Design Pattern in Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-173247614250617831</id><published>2010-04-03T14:46:00.000+06:00</published><updated>2010-04-03T14:54:48.284+06:00</updated><title type='text'>switch-case alternative in Python</title><content type='html'>Python has so 'switch - case' support unlike most other common languages. Of course you can use If-else block to serve your purpose. But there is an elegant alternative to 'switch-case' in python, using dictionary. Go though the following code (you should try running it).&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;# this is the default function&lt;br /&gt;def errorMessage():&lt;br /&gt;    print "Incorrect input. Please enter a number between 0 and 3."&lt;br /&gt;&lt;br /&gt;def fnc0():&lt;br /&gt;    print "This is function 0"&lt;br /&gt;&lt;br /&gt;def fnc1():&lt;br /&gt;    print "This is function 1"&lt;br /&gt;&lt;br /&gt;def fnc2():&lt;br /&gt;    print "This is function 2"&lt;br /&gt;&lt;br /&gt;def fnc3():&lt;br /&gt;    print "This is function 3"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;fncDict = {'0': fnc0, '1': fnc1, '2': fnc2, '3': fnc3}&lt;br /&gt;&lt;br /&gt;num = raw_input("Enter a number between 0 and 3")&lt;br /&gt;# if num is found as a key in the dictionary fncDict, then corresponding function is called&lt;br /&gt;# else the function errorMessage is called&lt;br /&gt;fncDict.get(num, errorMessage)()&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Hope you will find it interesting!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-173247614250617831?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/173247614250617831/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=173247614250617831' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/173247614250617831'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/173247614250617831'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2010/04/switch-case-alternative-in-python.html' title='switch-case alternative in Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-3325460205718593052</id><published>2010-04-03T02:22:00.000+06:00</published><updated>2010-04-03T02:26:56.222+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python file'/><category scheme='http://www.blogger.com/atom/ns#' term='write large file'/><category scheme='http://www.blogger.com/atom/ns#' term='random word'/><category scheme='http://www.blogger.com/atom/ns#' term='random string'/><title type='text'>Python code to generate random string</title><content type='html'>Today I wrote a small piece of Python code to generate random string. The string will have only the characters: 0-9, A-Z, a-z.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;    word = ''&lt;br /&gt;    for i in range(wordLen):&lt;br /&gt;        word += random.choice('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Here is the complete source code that generates a large file that has a random word one per line.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import random&lt;br /&gt;&lt;br /&gt;def get_random_word(wordLen):&lt;br /&gt;    word = ''&lt;br /&gt;    for i in range(wordLen):&lt;br /&gt;        word += random.choice('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')&lt;br /&gt;    return word&lt;br /&gt;    &lt;br /&gt;def main():&lt;br /&gt;    fout = open('word_list.txt', 'w')&lt;br /&gt;    for i in range(100000000):&lt;br /&gt;        wordLen = random.randint(5, 15)&lt;br /&gt;        word = ran_word(wordLen)&lt;br /&gt;        if i % 500000 == 0:&lt;br /&gt;            fout.close()&lt;br /&gt;            fout = open('word_list.txt', 'a')&lt;br /&gt;            print i&lt;br /&gt;        fout.write(word+"\n")&lt;br /&gt;    fout.close()&lt;br /&gt;&lt;br /&gt;main()&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-3325460205718593052?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/3325460205718593052/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=3325460205718593052' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3325460205718593052'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3325460205718593052'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2010/04/python-code-to-generate-random-string.html' title='Python code to generate random string'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-2539503093466358555</id><published>2010-03-30T22:01:00.000+06:00</published><updated>2010-03-30T22:12:18.972+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='CSV write in Python'/><category scheme='http://www.blogger.com/atom/ns#' term='unix'/><category scheme='http://www.blogger.com/atom/ns#' term='getch'/><title type='text'>getch() in Python - get a single character from keyboard</title><content type='html'>Today I needed to write a Python code for 'Press any key to continue' feature. First I wrote the code: &lt;code&gt;raw_input("Press Any Key to Continue: ")&lt;/code&gt;&lt;br /&gt;But actually it's not any key, you have to press enter followed by any key (or just enter). Then I started searching Google, came across several links, tried some of those and finally got something which is very close to what I need and modified the code to fit into my need. Here is the link that was almost exactly what I needed: &lt;a href="http://pyfaq.infogami.com/how-do-i-get-a-single-keypress-at-a-time"&gt;http://pyfaq.infogami.com/how-do-i-get-a-single-keypress-at-a-time&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Here is my getch function in Python:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import sys    &lt;br /&gt;import termios&lt;br /&gt;import fcntl&lt;br /&gt;&lt;br /&gt;def myGetch():&lt;br /&gt;    fd = sys.stdin.fileno()&lt;br /&gt;&lt;br /&gt;    oldterm = termios.tcgetattr(fd)&lt;br /&gt;    newattr = termios.tcgetattr(fd)&lt;br /&gt;    newattr[3] = newattr[3] &amp; ~termios.ICANON &amp; ~termios.ECHO&lt;br /&gt;    termios.tcsetattr(fd, termios.TCSANOW, newattr)&lt;br /&gt;&lt;br /&gt;    oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)&lt;br /&gt;    fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)&lt;br /&gt;&lt;br /&gt;    try:        &lt;br /&gt;        while 1:            &lt;br /&gt;            try:&lt;br /&gt;                c = sys.stdin.read(1)&lt;br /&gt;                break&lt;br /&gt;            except IOError: pass&lt;br /&gt;    finally:&lt;br /&gt;        termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)&lt;br /&gt;        fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And this one is also interesting but I couldn't make it work: &lt;a href="http://code.activestate.com/recipes/134892/"&gt;getch()-like unbuffered character reading from stdin on both Windows and Unix (Python)&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-2539503093466358555?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/2539503093466358555/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=2539503093466358555' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2539503093466358555'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2539503093466358555'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2010/03/getch-in-python-get-single-character.html' title='getch() in Python - get a single character from keyboard'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-1213097397727078872</id><published>2009-12-06T20:59:00.000+07:00</published><updated>2009-12-06T21:06:31.520+07:00</updated><title type='text'>How to define python source code encoding?</title><content type='html'>While using non-ASCII characters in your code, you might get this error: "SyntaxError: Non-ASCII character '\xc3' in file myprog.py on line 101, but no encoding declared;".&lt;br /&gt; &lt;br /&gt;Solution is to define encoding at the beginning of your source code.&lt;br /&gt;&lt;br /&gt;Syntax: &lt;code&gt;# -*- coding: desired_encoding -*-&lt;/code&gt;&lt;br /&gt;Example: &lt;code&gt;# -*- coding: iso-8859-1 -*-&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;For details check &lt;a href="http://www.python.org/dev/peps/pep-0263/"&gt;http://www.python.org/dev/peps/pep-0263/&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-1213097397727078872?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/1213097397727078872/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=1213097397727078872' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/1213097397727078872'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/1213097397727078872'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2009/12/how-to-define-python-source-code.html' title='How to define python source code encoding?'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-6041742027224457262</id><published>2009-12-01T03:02:00.000+07:00</published><updated>2009-12-01T03:09:28.049+07:00</updated><title type='text'>Python Console in gedit</title><content type='html'>Being an Ubuntu user gedit is my default editor for programming (sometimes I use netbeans though). Today I found a &lt;a href="http://techtunes.com.bd/linux/tune-id/3450/"&gt;post&lt;/a&gt; where the author wrote about gedit &lt;a href="http://live.gnome.org/Gedit/Plugins"&gt;plugins&lt;/a&gt;. I just played with it a bit and found that it has a Python Console! This is really interesting.&lt;br /&gt;&lt;br /&gt;You can also try installing the plugin:&lt;br /&gt;&lt;pre&gt;sudo apt-get install gedit-plugins&lt;/pre&gt;&lt;br /&gt;Now go to: &lt;pre&gt;edit &gt; preferences &gt; plugins&lt;/pre&gt; and select which plugins you want and enable the side pane &amp; bottom pane from the view menue.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-6041742027224457262?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/6041742027224457262/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=6041742027224457262' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6041742027224457262'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6041742027224457262'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2009/11/python-console-in-gedit.html' title='Python Console in gedit'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-1544060022952504913</id><published>2009-11-14T23:56:00.000+07:00</published><updated>2009-11-17T00:09:41.811+07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='twitter api'/><category scheme='http://www.blogger.com/atom/ns#' term='python'/><category scheme='http://www.blogger.com/atom/ns#' term='basic http authentication'/><title type='text'>Update twitter status using Python script</title><content type='html'>Recently I have written a Python script to update status message in twitter using their &lt;a href="http://apiwiki.twitter.com/Twitter-API-Documentation"&gt;api&lt;/a&gt;. Let me share the code here:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import urllib&lt;br /&gt;import urllib2&lt;br /&gt;import base64&lt;br /&gt;import httplib&lt;br /&gt;import socket&lt;br /&gt;&lt;br /&gt;## authenticate module is used for http basic authentication. found in '&lt;a href="http://www.voidspace.org.uk/python/articles/urllib2.shtml"&gt;urllib2 missing manual&lt;/a&gt;'&lt;br /&gt;def authenticate(username, password):&lt;br /&gt;   password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()&lt;br /&gt;   top_level_url = 'http://twitter.com/'&lt;br /&gt;   password_mgr.add_password(None, top_level_url, username, password)&lt;br /&gt;   handler = urllib2.HTTPBasicAuthHandler(password_mgr)&lt;br /&gt;   opener = urllib2.build_opener(handler)&lt;br /&gt;&lt;br /&gt;   return opener&lt;br /&gt;&lt;br /&gt;## updates twitter status given the status, user name (id or email) and password &lt;br /&gt;def update_status(status, user, password):   &lt;br /&gt;   data = {'status' : status}   &lt;br /&gt;   data = urllib.urlencode(data)&lt;br /&gt;  &lt;br /&gt;   url = 'http://twitter.com/statuses/update.xml'&lt;br /&gt;  &lt;br /&gt;   opener = authenticate(user, password)&lt;br /&gt;   result = ''&lt;br /&gt;   try:&lt;br /&gt;       handle = opener.open(url, data = data)&lt;br /&gt;       result = handle.read()&lt;br /&gt;       handle.close()   &lt;br /&gt;       return&lt;br /&gt;   except Exception, detail:&lt;br /&gt;       print "Err ", detail&lt;br /&gt;&lt;br /&gt;#program starts from here   &lt;br /&gt;main()&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Hope you will find it useful. Let me know if you have any suggestion to make my code better. It will be appreciated.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-1544060022952504913?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/1544060022952504913/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=1544060022952504913' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/1544060022952504913'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/1544060022952504913'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2009/11/update-twitter-status-using-python.html' title='Update twitter status using Python script'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-3886667361160434700</id><published>2009-11-12T01:01:00.000+07:00</published><updated>2009-11-12T01:15:41.432+07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python unicode'/><title type='text'>Python UNICODE encode / decode error</title><content type='html'>Today I was trying to scrape a Spanish site and got into trouble with some Spanish characters. I had to parse some messages from that Spanish website and post into twitter using my Python script. But for some reasons Spanish characters didn't show up in twitter status updates.&lt;br /&gt;&lt;br /&gt;I was in some trouble with the following error messages:&lt;br /&gt;UnicodeDecodeError: 'utf8' codec can't decode bytes in position 5778-5781: invalid data&lt;br /&gt;UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in position 5778: ordinal not in range(128)&lt;br /&gt;&lt;br /&gt;Then I did Googling for some time and got this &lt;a href="http://eric.themoritzfamily.com/2008/11/21/python-encodings-and-unicode/"&gt;very useful link&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I used this code to get the content of the website:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import codecs&lt;br /&gt;import urllib2&lt;br /&gt;&lt;br /&gt;url = '' # put the URL here&lt;br /&gt;usock = urllib2.urlopen(url)&lt;br /&gt;Reader = codecs.getreader("latin_1")&lt;br /&gt;fh = Reader(usock)&lt;br /&gt;data = fh.read()&lt;br /&gt;fh.close()&lt;br /&gt;usock.close()&lt;br /&gt;data = data.encode("latin_1")&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Though I first used utf-8 encoding rather than latin_1, but when I got this error: "UnicodeDecodeError: 'utf8' codec can't decode bytes in position 5778-5781: invalid data" I found that the website is using latin_1 character set (from html source) not utf-8.&lt;br /&gt;&lt;br /&gt;Don't forget to check the &lt;a href="http://www.python.org/doc/2.5.2/lib/module-codecs.html"&gt;codecs module&lt;/a&gt;. Btw, I am using Python 2.5.2. :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-3886667361160434700?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/3886667361160434700/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=3886667361160434700' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3886667361160434700'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3886667361160434700'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2009/11/python-unicode-encode-decode-error.html' title='Python UNICODE encode / decode error'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-5016474170422369603</id><published>2009-10-04T00:18:00.000+07:00</published><updated>2009-10-04T00:25:09.999+07:00</updated><title type='text'>Python programmer in Malaysia</title><content type='html'>One of my friend is looking for python developers located in Malaysia. If you are interested please contact him: yfaizal at gmail.com&lt;br /&gt;&lt;br /&gt;Thanks.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-5016474170422369603?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/5016474170422369603/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=5016474170422369603' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/5016474170422369603'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/5016474170422369603'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2009/10/python-programmer-in-malaysia.html' title='Python programmer in Malaysia'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-7137919557530322596</id><published>2009-08-22T12:09:00.000+07:00</published><updated>2009-08-22T12:14:45.691+07:00</updated><title type='text'>Google friend connect in Love Python</title><content type='html'>I have added Google friend connect widget in this blog so the followers can socialize with each other. You can also do it using the 'follower' gadget. You can read about Google friend connect here: &lt;a href="http://www.google.com/intl/en/press/annc/20080512_friend_connect.html"&gt;http://www.google.com/intl/en/press/annc/20080512_friend_connect.html&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-7137919557530322596?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/7137919557530322596/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=7137919557530322596' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/7137919557530322596'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/7137919557530322596'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2009/08/google-friend-connect-in-love-python.html' title='Google friend connect in Love Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-7668186276765508085</id><published>2009-08-02T00:37:00.000+07:00</published><updated>2009-08-02T00:49:04.696+07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='random elements'/><title type='text'>randomize elements in a file or list using Python</title><content type='html'>Last week I had to populate a mysql table with some random user names. First problem was to get those names - which I managed writing a crawler with Python. Using the program I got a text file with around 500 names listed in alphabetical order. But I didn't want to insert those in the same order as it will look odd (you don't want to get a list of opponent player's name all starting with 'A' in a game, right?). Then I decided to write some python code to generate another file with names in random order. The logic will be simple. First load all the names in a list, and from that list get a random element and put in another list. Delete the element from the initial list. Before I started coding, I googled for a while and found an interesting solution!&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import random&lt;br /&gt;...&lt;br /&gt;count = names.__len__() &lt;br /&gt;# names is the list containing names in alphabetical order&lt;br /&gt;names = random.sample(names, count) &lt;br /&gt;# now names contain names in random order!&lt;br /&gt;...&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Another Python magic!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-7668186276765508085?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/7668186276765508085/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=7668186276765508085' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/7668186276765508085'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/7668186276765508085'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2009/08/randomize-elements-in-file-or-list.html' title='randomize elements in a file or list using Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-6170936449611220273</id><published>2009-07-07T00:30:00.000+07:00</published><updated>2009-07-07T00:53:32.153+07:00</updated><title type='text'>Should a Python programmer be paid higher than a PHP / Perl / Java programmer ?</title><content type='html'>This question might sound stupid, but I have been wondering about this. Say I hire two developers with similar experience and expertise in my company. One is for a Python project and another one is for Java project. Should they get same compensation? A couple of years back, when I heard about Python from one of my senior friend (who is a CTO of a software firm, a very experienced guy), he told me that he likes Python because, development speed is lot faster in this language. He, from his experience believes that if a project takes six months to be completed using Java, four months should be good enough if it's done using Python. He was also planning for a project where he choose Python, and his logic was, he will use four Python developers for the project and if he choose Java instead of Python, it would take 10 developers to complete the project (same time frame). Then I said to him, "so, are you going to pay higher to the Python devs?" ... he just smiled :) ...&lt;br /&gt;&lt;br /&gt;So folks, what do you think? Should the Python devs get more? Share your thoughts.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-6170936449611220273?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/6170936449611220273/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=6170936449611220273' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6170936449611220273'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6170936449611220273'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2009/07/should-python-programmer-be-paid-higher.html' title='Should a Python programmer be paid higher than a PHP / Perl / Java programmer ?'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-1534607528951769142</id><published>2009-06-22T01:24:00.000+07:00</published><updated>2009-06-22T01:29:56.561+07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python Jobs'/><title type='text'>Python Job - Web Development</title><content type='html'>Python is slowly getting popular in Bangladesh. Today I have browsed a &lt;a href="http://www.bdjobs-server.com/bdjobs/jobs/jobs.asp?ID=149629+&amp;CID="&gt;job site&lt;/a&gt; and found one job advertisement for Python programmer. A company named &lt;a href="http://www.ritbd.com/"&gt;Roots Information Technology&lt;/a&gt; is looking for four Python developers. Click &lt;a href="http://www.bdjobs-server.com/bdjobs/jobs/jobs.asp?ID=149629+&amp;CID="&gt;here&lt;/a&gt; for the job details.&lt;br /&gt;&lt;br /&gt;Hopefully we will find more companies looking for Python programmers in Bangladesh in neat future.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-1534607528951769142?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/1534607528951769142/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=1534607528951769142' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/1534607528951769142'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/1534607528951769142'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2009/06/python-job-web-development.html' title='Python Job - Web Development'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-2099287489025303735</id><published>2009-03-10T13:30:00.000+06:00</published><updated>2009-05-16T10:21:18.332+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python http get'/><category scheme='http://www.blogger.com/atom/ns#' term='python http post'/><title type='text'>Updated python code for get html source</title><content type='html'>Yesterday I made little update to my function get_html_source() that gets the content of a page. I did so because I found that my previous function didn't support HTTP POST. Now the code supports both HTTP GET and HTTP POST. It also returns the cookiejar along with the html content of the page. &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;def get_html_source(url, referer = '', data = 0, cj = 0, retry_counter = 0):&lt;br /&gt;    if retry_counter &gt; 0:&lt;br /&gt;        print 'Trying Again...'&lt;br /&gt;    if retry_counter &gt; 3:&lt;br /&gt;        print 'Could not get source from url:', url&lt;br /&gt;        return '', ''&lt;br /&gt;    try:&lt;br /&gt;        if cj:&lt;br /&gt;            opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))&lt;br /&gt;        else:&lt;br /&gt;            opener = urllib2.build_opener()&lt;br /&gt;&lt;br /&gt;        opener.addheaders = [('Referer', referer),&lt;br /&gt;                 ('Content-Type', 'application/x-www-form-urlencoded'),&lt;br /&gt;                 ('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14'),&lt;br /&gt;                 ('Accept-Encoding', 'gzip,deflate')]&lt;br /&gt;&lt;br /&gt;        if data:&lt;br /&gt;            # HTTP POST&lt;br /&gt;            usock = opener.open(url, data)&lt;br /&gt;        else:&lt;br /&gt;            # HTTP GET&lt;br /&gt;            usock = opener.open(url)&lt;br /&gt;        &lt;br /&gt;        content = decode(usock) # I think I have already written the code of decode function&lt;br /&gt;                                # in another post. If you can't find it, just leave a comment&lt;br /&gt;                                # here and I shall post the code again.&lt;br /&gt;        usock.close()                &lt;br /&gt;        return content, cj&lt;br /&gt;    except urllib2.HTTPError, e:&lt;br /&gt;        print 'The server couldn\'t fulfill the request. for url: ', url&lt;br /&gt;        print 'Error code: ', e.code&lt;br /&gt;        return get_html_source(url, referer, data, cj, retry_counter + 1)            &lt;br /&gt;    except urllib2.URLError, e:&lt;br /&gt;        print 'We failed to reach a server.'&lt;br /&gt;        print 'Reason: ', e.reason&lt;br /&gt;        return get_html_source(url, referer, data, cj, retry_counter + 1)&lt;br /&gt;            &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Please suggest any necessary update / modification of this code.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-2099287489025303735?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/2099287489025303735/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=2099287489025303735' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2099287489025303735'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2099287489025303735'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2009/03/updated-python-code-for-get-html-source.html' title='Updated python code for get html source'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-682495288311972534</id><published>2009-01-05T10:16:00.000+06:00</published><updated>2009-01-05T10:32:54.824+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='reduce image size'/><title type='text'>Resize image before uploading</title><content type='html'>Where Internet connection is slow, it takes too much time to upload images. Few days ago I was trying to upload some images in facebook and it seemed to take forever. The I wrote the following python program to reduce the image size (around 4MB to  around 100 KB!):&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import Image&lt;br /&gt;import os, sys&lt;br /&gt;&lt;br /&gt;# adjust width and height to your needs&lt;br /&gt;width = 800&lt;br /&gt;height = 600&lt;br /&gt;&lt;br /&gt;for root, dirs, files in os.walk('./'):&lt;br /&gt;    for name in files:       &lt;br /&gt;        filename = os.path.join(root, name)&lt;br /&gt;        if filename.endswith('jpg'):&lt;br /&gt;            print filename&lt;br /&gt;            imin = Image.open(filename)&lt;br /&gt;            imout = imin.resize((width, height), Image.BICUBIC) &lt;br /&gt;            imout.save(filename)&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-682495288311972534?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/682495288311972534/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=682495288311972534' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/682495288311972534'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/682495288311972534'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2009/01/resize-image-before-uploading.html' title='Resize image before uploading'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-2280854122985633943</id><published>2008-10-28T23:20:00.000+06:00</published><updated>2008-10-28T23:32:55.990+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='get remote file size (http)'/><title type='text'>get remote file size through http</title><content type='html'>Couple of days ago I wrote this code.&lt;br /&gt;&lt;br /&gt;The requirement is to get the size of a remote file (http). For example: the Python program needs to find the size of the file, http://abc.com/dir/file1.mp3&lt;br /&gt;&lt;br /&gt;Now here is a very stupid solution for this:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import urllib2&lt;br /&gt;&lt;br /&gt;url = 'http://abc.com/dir/file1.mp3'&lt;br /&gt;usock = urllib2.urlopen(url)&lt;br /&gt;data = usock.read()&lt;br /&gt;size = data.__len__() # size in bytes&lt;br /&gt;size = size / 1024.0 # in KB (Kilo Bytes)&lt;br /&gt;size = size / 1024.0 # size in MB (Mega Bytes)&lt;br /&gt;...&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The stupidity happens in this line: &lt;code&gt;data = usock.read()&lt;/code&gt; where the whole file is being read to get it's size! This solution came to my mind first. But soon I understood that the file size can be found from the http response header. Here is a much better solution:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import urllib2&lt;br /&gt;&lt;br /&gt;url = 'http://abc.com/dir/file1.mp3'&lt;br /&gt;usock = urllib2.urlopen(url)&lt;br /&gt;size =  usock.info().get('Content-Length')&lt;br /&gt;if size is None:&lt;br /&gt;    size = 0&lt;br /&gt;size = float(size) # in bytes&lt;br /&gt;size = size / 1024.0 # in KB (Kilo Bytes)&lt;br /&gt;size = size / 1024.0 # size in MB (Mega Bytes)&lt;br /&gt;...&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-2280854122985633943?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/2280854122985633943/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=2280854122985633943' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2280854122985633943'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2280854122985633943'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/10/get-remote-file-size-through-http.html' title='get remote file size through http'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-2714982942022399580</id><published>2008-09-27T22:02:00.000+06:00</published><updated>2008-09-27T22:07:14.846+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='remove duplicate'/><title type='text'>Remove duplicate items from a list using set</title><content type='html'>A common problem beginners face is to remove duplicate items from a list. In Python it can be done easily. First make a set from the list and then make a list for that set.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-size:110%;"&gt;myList = list(set(myList))&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Here is a python example:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&gt;&gt;&gt; myList = [1, 2, 3, 3, 2, 2, 4, 5, 5]&lt;br /&gt;&gt;&gt;&gt; myList&lt;br /&gt;[1, 2, 3, 3, 2, 2, 4, 5, 5]&lt;br /&gt;&gt;&gt;&gt; myList = list(set(myList))&lt;br /&gt;&gt;&gt;&gt; myList&lt;br /&gt;[1, 2, 3, 4, 5]&lt;br /&gt;&gt;&gt;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Let me know if you use any different technique to remove duplicates from a list.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-2714982942022399580?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/2714982942022399580/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=2714982942022399580' title='12 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2714982942022399580'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2714982942022399580'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/09/remove-duplicate-items-from-list-using.html' title='Remove duplicate items from a list using set'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>12</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-1914576209592400969</id><published>2008-09-08T22:24:00.000+06:00</published><updated>2008-09-08T22:29:20.423+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='cookie'/><category scheme='http://www.blogger.com/atom/ns#' term='proxy'/><title type='text'>use proxy and cookie together in Python</title><content type='html'>Here is an example code in Python that fetches an URL and writes the content to a text file. The purpose of publishing the code is to demonstrate how to use Proxy and Cookie together in an opener.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-size:110%;"&gt;import urllib2&lt;br /&gt;import cookielib&lt;br /&gt;&lt;br /&gt;# create cookiejar to store cookie&lt;br /&gt;cj = cookielib.CookieJar()&lt;br /&gt;&lt;br /&gt;# IP:PORT&lt;br /&gt;proxy_address = '66.98.208.8:3128' # change the IP:PORT, this one is for example&lt;br /&gt;&lt;br /&gt;# create the proxy handler&lt;br /&gt;proxy_handler = urllib2.ProxyHandler({'http': proxy_address})&lt;br /&gt;&lt;br /&gt;# create opener&lt;br /&gt;opener = urllib2.build_opener(proxy_handler, urllib2.HTTPCookieProcessor(cj))&lt;br /&gt;&lt;br /&gt;# install the opener&lt;br /&gt;urllib2.install_opener(opener)&lt;br /&gt;&lt;br /&gt;# url to browse / visit&lt;br /&gt;url = "http://www....com/" # change the url&lt;br /&gt;&lt;br /&gt;req=urllib2.Request(url)&lt;br /&gt;&lt;br /&gt;data=urllib2.urlopen(req).read()&lt;br /&gt;&lt;br /&gt;print data&lt;br /&gt;&lt;br /&gt;# now write the data to a text file&lt;br /&gt;&lt;br /&gt;# create file handler&lt;br /&gt;fh = open('page.txt', 'w')&lt;br /&gt;&lt;br /&gt;data = "".join(data)&lt;br /&gt;&lt;br /&gt;# write to file&lt;br /&gt;fh.write(data)&lt;br /&gt;&lt;br /&gt;# close the file handler&lt;br /&gt;fh.close()&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;Hope you will find the code useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-1914576209592400969?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/1914576209592400969/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=1914576209592400969' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/1914576209592400969'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/1914576209592400969'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/09/use-proxy-and-cookie-together-in-python.html' title='use proxy and cookie together in Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-6990988250565242088</id><published>2008-09-04T20:44:00.000+06:00</published><updated>2008-09-04T21:12:56.232+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PyS60'/><category scheme='http://www.blogger.com/atom/ns#' term='Python for Mobile Phone'/><title type='text'>Py2SIS create sis file to make standalone application</title><content type='html'>You have coded the program and tested it using PyS60 emulator or in your mobile phone. Now you want to make standalone application out of your Python code to deploy in mobile phones. You have to create SIS (Symbian Installation System) file. &lt;br /&gt;&lt;br /&gt;Format of the command is:&lt;br /&gt;&lt;pre&gt;py2sis &lt;src&gt; [sisfile] [--uid=0x12345678] [--appname=myapp] &lt;br /&gt;[--presdk20] [--leavetemp]&lt;/pre&gt;&lt;br /&gt;I used the following command to create SIS file for my program:&lt;br /&gt;&lt;pre&gt;F:\Nokia\Tools\Python_for_Series_60\py2sis&gt;py2sis.exe &lt;br /&gt;dse_stock_tracker.py dse.sis --uid 0x12345678 &lt;br /&gt;--appname=DSEStockPriceTracker&lt;/pre&gt;&lt;br /&gt;If you want to know details about py2sis, get the book (ebook is there) "Programming with Python for Series 60 Platform" and go to chapter 14. The book is freely available.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-6990988250565242088?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/6990988250565242088/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=6990988250565242088' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6990988250565242088'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6990988250565242088'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/09/py2sis-create-sis-file-to-make.html' title='Py2SIS create sis file to make standalone application'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-5339122540157455391</id><published>2008-09-01T01:49:00.000+06:00</published><updated>2008-09-01T01:57:32.592+06:00</updated><title type='text'>The A-Z of programming languages: Python</title><content type='html'>Computer world published an interesting article - &lt;a href="http://www.computerworld.com/action/article.do?command=viewArticleBasic&amp;articleId=9113380&amp;source=rss_topic122"&gt;&lt;span style="font-weight:bold;"&gt;The A-Z of programming languages: Python&lt;/span&gt;&lt;/a&gt;. Actually it's an interview of &lt;a href="http://en.wikipedia.org/wiki/Guido_van_Rossum"&gt;Guido van Rossum&lt;/a&gt; - the creator of Python language. There he answers various questions regarding Python. I think it's a must read for Python fans / enthusiasts. So can't help but sharing the link with you.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-5339122540157455391?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/5339122540157455391/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=5339122540157455391' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/5339122540157455391'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/5339122540157455391'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/08/a-z-of-programming-languages-python.html' title='The A-Z of programming languages: Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-1001562672938823101</id><published>2008-08-29T01:43:00.000+06:00</published><updated>2010-10-30T10:23:49.461+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='regular expression'/><title type='text'>Regular Expression in Python</title><content type='html'>'How to learn regular expression in Python?' - a very common question from the beginners or Python newbies. Well... if you can use regular expression in Perl or PHP, then it's not very different in Python.&lt;br /&gt;&lt;br /&gt;And if you are completely new to regular expression and want to learn it, then you can follow the following guideline:&lt;br /&gt;&lt;br /&gt;[Update on Oct 30, 2010]: I think you should start with &lt;a href="http://www.youtube.com/watch?v=kWyoYtvJpe4"&gt;this video on regular expression&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;At first, you should be to read &lt;a href="http://www.amk.ca/python/howto/regex/regex.html"&gt;Regular Expression HowTo&lt;/a&gt; by A.M. Kuchling. Read it carefully and read it at least twice :)&lt;br /&gt;&lt;br /&gt;So... now you have finished reading Regular Expression How To and still not very confident. Don't worry. It's time to dive into regular expression. Just go through &lt;a href="http://diveintopython.org/regular_expressions/index.html"&gt;Chapter 7 Regular Expressions&lt;/a&gt; of Dive Into Python. Don't forget to code each and every example. There are some nice case studies. Those will help (it was really helpful in my case).&lt;br /&gt;&lt;br /&gt;And now it's time for you to check details about the &lt;a href="http://www.python.org/doc/current/lib/module-re.html"&gt;re module&lt;/a&gt; from python doc.&lt;br /&gt;&lt;br /&gt;By this time you should be a good player of regular expressions and can use it to solve practical problems.&lt;br /&gt;&lt;br /&gt;Still want to be a master? Then you should read this: &lt;a href="http://www.amazon.com/gp/product/0596528124?ie=UTF8&amp;tag=lovpyt-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0596528124"&gt;Mastering Regular Expressions&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=lovpyt-20&amp;l=as2&amp;o=1&amp;a=0596528124" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /&gt; (I haven't read it yet though ;)&lt;br /&gt;&lt;br /&gt;If you have to work with regular expressions frequently, you can check this one: &lt;a href="http://www.amazon.com/gp/product/0596514271?ie=UTF8&amp;tag=lovpyt-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0596514271"&gt;Regular Expression Pocket Reference: Regular Expressions for Perl, Ruby, PHP, Python, C, Java and .NET (Pocket Reference (O'Reilly))&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=lovpyt-20&amp;l=as2&amp;o=1&amp;a=0596514271" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /&gt;&lt;br /&gt;&lt;br /&gt;Hopefully learning regular expressions will empower you more!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-1001562672938823101?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/1001562672938823101/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=1001562672938823101' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/1001562672938823101'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/1001562672938823101'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/08/regular-expression-in-python.html' title='Regular Expression in Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-4744933095635826487</id><published>2008-08-27T09:41:00.000+06:00</published><updated>2008-08-27T09:52:18.276+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python Jobs'/><title type='text'>Looking for Python Jobs? Check Job Boards</title><content type='html'>Sometime I see people wondering about the Job market of Python. Now days kids are more interested about their career :) ... So I have decided to collect Python Job board addresses and post the links here. Note that this page will be updated whenever I find any new link. You can also help me by posting comments.&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a style="font-weight: bold;" href="http://www.python.org/community/jobs/"&gt;Python Job Board&lt;/a&gt;: This is a community maintained page. It's frequently updated. Also there is a &lt;a href="http://wiki.python.org/moin/VolunteerOpportunities"&gt;volunteer opportunity&lt;/a&gt; page.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-4744933095635826487?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/4744933095635826487/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=4744933095635826487' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/4744933095635826487'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/4744933095635826487'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/08/looking-for-python-jobs-check-job.html' title='Looking for Python Jobs? Check Job Boards'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-8728462373009949404</id><published>2008-08-26T23:38:00.000+06:00</published><updated>2008-08-27T00:16:32.180+06:00</updated><title type='text'>Is Python only for web programming?</title><content type='html'>As a Python enthusiast/advocate I always have to face some common questions about Python from friends, juniors, colleagues... One of those is, "Is Python used only for web programming?"&lt;br /&gt;&lt;br /&gt;So I think I better write the answer here :)&lt;br /&gt;&lt;br /&gt;And the answer is NO. Python is used in lots of places:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Web Programming: Python is heavily used in Web Programming. There is a great CMS named Plone, developed in Python. There are also some good web frameworks. Also the Google Application Engine is developed using Python&lt;/li&gt;&lt;li&gt;Desktop Computing: Python can be used to develop software for desktop. There are multiple ways to develop GUI for your python software. You can use Tkinter, wxPython etc.&lt;/li&gt;&lt;li&gt;Distributed Computing: It's another field where Python is used effectively. Once I heard about the RIVER project (I forgot the link) which is developed using Python.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Mobile Phone Programming: Yes, Python can be used in your mobile phones. Nokia developed PyS60 to run in Symbian S60 (series 60) phones. There is also a book available for PyS60 &lt;a href="http://www.amazon.com/gp/product/0470515058?ie=UTF8&amp;amp;tag=lovpyt-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0470515058"&gt;Mobile Python: Rapid prototyping of applications on the mobile platform (Symbian Press)&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=lovpyt-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=0470515058" alt="" style="border: medium none  ! important; margin: 0px ! important;" width="1" border="0" height="1" /&gt;&lt;/li&gt;&lt;li&gt;Game Programming!: There is PyGame. So if you are really want to have some fun while coding, want to develop an interesting game, Python is there for you with pygame. There are books available for pygame: &lt;a href="http://www.amazon.com/gp/product/1590598725?ie=UTF8&amp;amp;tag=lovpyt-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=1590598725"&gt;Beginning Game Development with Python and Pygame: From Novice to Professional (Beginning from Novice to Professional)&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=lovpyt-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=1590598725" alt="" style="border: medium none  ! important; margin: 0px ! important;" width="1" border="0" height="1" /&gt;, &lt;a href="http://www.amazon.com/gp/product/1584502584?ie=UTF8&amp;amp;tag=lovpyt-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=1584502584"&gt;Game Programming With Python (Game Development Series)&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=lovpyt-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=1584502584" alt="" style="border: medium none  ! important; margin: 0px ! important;" width="1" border="0" height="1" /&gt;&lt;/li&gt;&lt;li&gt;Scientific computing: There is Python module available for numerical programming (numpy) and also there is another module that can be used for programming in bioinformatics. There are two complete books available for this: &lt;a href="http://www.amazon.com/gp/product/0763751863?ie=UTF8&amp;amp;tag=lovpyt-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0763751863"&gt;Python For Bioinformatics (Jones and Bartlett Series in Biomedical Informatics)&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=lovpyt-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=0763751863" alt="" style="border: medium none  ! important; margin: 0px ! important;" width="1" border="0" height="1" /&gt; and &lt;a href="http://www.amazon.com/gp/product/3527320946?ie=UTF8&amp;amp;tag=lovpyt-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=3527320946"&gt;Bioinformatics Programming in Python: A Practical Course for Beginners&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=lovpyt-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=3527320946" alt="" style="border: medium none  ! important; margin: 0px ! important;" width="1" border="0" height="1" /&gt;&lt;/li&gt;&lt;/ul&gt;Also check the page from wikipedia &lt;a href="http://en.wikipedia.org/wiki/Python_software"&gt;List of Python Software&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Last but not the least, Python is one of the three official programming languages of Google!&lt;br /&gt;&lt;br /&gt;Please add if I missed anything important.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-8728462373009949404?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/8728462373009949404/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=8728462373009949404' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/8728462373009949404'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/8728462373009949404'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/08/is-python-only-for-web-programming.html' title='Is Python only for web programming?'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-7421943068118036738</id><published>2008-08-25T21:58:00.000+06:00</published><updated>2008-08-25T22:08:06.335+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python for Mobile Phone'/><title type='text'>PyS60 - download file using urlretrieve</title><content type='html'>The following function written in Python downloads a remote file to mobile phone.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import urllib&lt;br /&gt;&lt;br /&gt;def download_file():&lt;br /&gt;    remoteFileName = u"http://example.com/a.txt" # set the url here&lt;br /&gt;    localFileName = u"c:\\items.txt"&lt;br /&gt;    urllib.urlretrieve(remoteFileName, localFileName)&lt;br /&gt;&lt;br /&gt;download_file()&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The code was used in my 'DSE Price Tracker' application in order to download the list of companies.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-7421943068118036738?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/7421943068118036738/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=7421943068118036738' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/7421943068118036738'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/7421943068118036738'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/08/pys60-download-file-using-urlretrieve.html' title='PyS60 - download file using urlretrieve'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-3865249017672207238</id><published>2008-08-23T00:25:00.000+06:00</published><updated>2008-08-23T00:49:44.996+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PyS60'/><category scheme='http://www.blogger.com/atom/ns#' term='Python for Mobile Phone'/><title type='text'>Create selection list from a file in PyS60</title><content type='html'>Let's come back to the project - DSE price tracker. The next step was to load all the company names from a file (stored in the mobile phone memory) and display in the selection list. The file contains the company names, one per line.&lt;br /&gt;&lt;br /&gt;So I wrote the following code:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import appuifw&lt;br /&gt;&lt;br /&gt;def get_data_from_file():&lt;br /&gt;    fp = open('c:\\names.txt', 'r')&lt;br /&gt;    li = fp.readlines()&lt;br /&gt;    fp.close()&lt;br /&gt;    compList = []&lt;br /&gt;    for item in li:&lt;br /&gt;        item = item.decode("utf-8")&lt;br /&gt;        compList.append(item)   &lt;br /&gt;    return compList&lt;br /&gt;&lt;br /&gt;L = get_data_from_file()&lt;br /&gt;index = appuifw.selection_list(choices=L , search_field=1)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Yes, it works. Note that you must decode each line to unicode (utf-8). (&lt;code&gt;item = item.decode("utf-8")&lt;/code&gt;)&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_A2NamGQmyCc/SK8Gk17TDGI/AAAAAAAAAaY/NqpewJ3hzQI/s1600-h/dse_list2.PNG"&gt;&lt;img style="float:center; margin:0 0 10px 10px;cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_A2NamGQmyCc/SK8Gk17TDGI/AAAAAAAAAaY/NqpewJ3hzQI/s200/dse_list2.PNG" border="0" alt=""id="BLOGGER_PHOTO_ID_5237412121676024930" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;But wait, what are those small boxes beside each name? I guess it's the newline character ('\n') after each line. So I need to replace '\n' with a blank ''.&lt;br /&gt;Here is the modified get_data_from_file()&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;def get_data_from_file():&lt;br /&gt;    fp = open('c:\\names.txt', 'r')&lt;br /&gt;    li = fp.readlines()&lt;br /&gt;    fp.close()&lt;br /&gt;    compList = []&lt;br /&gt;    for item in li:&lt;br /&gt;        item = item.replace('\n', '')&lt;br /&gt;        item = item.replace('\r', '')&lt;br /&gt;        item = item.decode("utf-8")&lt;br /&gt;        compList.append(item)   &lt;br /&gt;    return compList&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now it looks fine!&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_A2NamGQmyCc/SK8H05yiTgI/AAAAAAAAAag/mnyNYrY9xdM/s1600-h/dse_list3.PNG"&gt;&lt;img style="float:middle; margin:0 0 10px 10px;cursor:pointer; cursor:hand;" src="http://3.bp.blogspot.com/_A2NamGQmyCc/SK8H05yiTgI/AAAAAAAAAag/mnyNYrY9xdM/s200/dse_list3.PNG" border="0" alt=""id="BLOGGER_PHOTO_ID_5237413497102552578" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Next to-do is to grab the file from a remote URL and store it in mobile phone memory, then display the list.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-3865249017672207238?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/3865249017672207238/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=3865249017672207238' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3865249017672207238'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3865249017672207238'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/08/create-selection-list-from-file-in.html' title='Create selection list from a file in PyS60'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_A2NamGQmyCc/SK8Gk17TDGI/AAAAAAAAAaY/NqpewJ3hzQI/s72-c/dse_list2.PNG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-3047521380321334832</id><published>2008-08-22T01:27:00.000+06:00</published><updated>2008-08-22T01:35:13.316+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OOP in Python'/><title type='text'>Designing Class in Python - Pythonic way</title><content type='html'>I found two very interesting discussions on writing / designing class in Python. If you still in search of the beauty of object oriented programming in Python, check the following links:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://groups.google.com/group/comp.lang.python/browse_thread/thread/4911cfc981553692/50c4049f18512bbd?show_docid=50c4049f18512bbd#"&gt;Is my thinking Pythonic?&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://groups.google.com/group/comp.lang.python/browse_thread/thread/b4001042e59bcc29/"&gt;Handling Property and internal ('__') attribute inheritance and creation&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;Enjoy Python :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-3047521380321334832?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/3047521380321334832/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=3047521380321334832' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3047521380321334832'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3047521380321334832'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/08/designing-class-in-python-pythonic-way.html' title='Designing Class in Python - Pythonic way'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-6791495940216281553</id><published>2008-08-21T22:51:00.000+06:00</published><updated>2008-08-21T23:20:18.024+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PyS60'/><category scheme='http://www.blogger.com/atom/ns#' term='Python for Mobile Phone'/><title type='text'>Create a selection list in PyS60</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_A2NamGQmyCc/SK2fXlm8s_I/AAAAAAAAAaQ/AmaNNtDlgUw/s1600-h/dse_list.PNG"&gt;&lt;img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;" src="http://2.bp.blogspot.com/_A2NamGQmyCc/SK2fXlm8s_I/AAAAAAAAAaQ/AmaNNtDlgUw/s200/dse_list.PNG" border="0" alt=""id="BLOGGER_PHOTO_ID_5237017169283036146" /&gt;&lt;/a&gt;&lt;br /&gt;Creating a selection list for my software - 'DSE Stock Tracker' was very important task. It will show the list of companies of Dhaka Stock Exchange. So for demo I tried to create a list of four companies. Here is the code:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import appuifw&lt;br /&gt;&lt;br /&gt;L = ['DHAKABANK', 'AIMS1STMF', 'EXIMBANK', 'TRUSTBANK']&lt;br /&gt;index = appuifw.selection_list(choices=L , search_field=1)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;I tried to run the program but got the following error:&lt;br /&gt;&lt;code&gt;SymbianError: [Errno -6] KErrArgument&lt;/code&gt;&lt;br /&gt;Oh, I forgot to add the 'u' (u for unicode) before each string. So I changed my code and it works.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import appuifw&lt;br /&gt;&lt;br /&gt;L = [u'DHAKABANK', u'AIMS1STMF', u'EXIMBANK', u'TRUSTBANK']&lt;br /&gt;index = appuifw.selection_list(choices=L , search_field=1)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Now, as there are hundreds of companies, it's not wise to write every name in the code. So the next to-do is load the list from a file.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-6791495940216281553?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/6791495940216281553/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=6791495940216281553' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6791495940216281553'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6791495940216281553'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/08/create-selection-list-in-pys60.html' title='Create a selection list in PyS60'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_A2NamGQmyCc/SK2fXlm8s_I/AAAAAAAAAaQ/AmaNNtDlgUw/s72-c/dse_list.PNG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-3794147924863789404</id><published>2008-08-18T20:48:00.001+06:00</published><updated>2008-08-18T21:21:24.318+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python'/><title type='text'>'DSE Stock Tracker' in First BdOSN Code Sprint</title><content type='html'>I am back from the first &lt;a href="http://bdosn.org"&gt;BdOSN&lt;/a&gt; code sprint - the first of it's kind in our country - Bangladesh. It was held at &lt;a href="http://www.sust.edu/"&gt;SUST&lt;/a&gt; (Shah Jalal University of Science &amp; Technology), Sylhet - one of the most beautiful places in Bangladesh. I did my graduation from this university :)&lt;br /&gt;&lt;br /&gt;There I lead a project named 'DSE Stock Tracker'. It shows real-time (4 minutes delay) stock prices from Dhaka Stock Exchange to your mobile. The mobile client was developed in Python (PyS60). &lt;br /&gt;&lt;br /&gt;The whole system has three parts:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;A spider that harvests data from dse website and stores in mysql database&lt;/li&gt;&lt;li&gt;An API for mobile application/client&lt;/li&gt;&lt;li&gt;A mobile client&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;All the parts are developed using Python.&lt;br /&gt;&lt;br /&gt;I shall write my experience, challenges faced and how I solved them in next several posts. Stay tuned!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-3794147924863789404?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/3794147924863789404/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=3794147924863789404' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3794147924863789404'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3794147924863789404'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/08/dse-stock-tracker-in-first-bdosn-code.html' title='&apos;DSE Stock Tracker&apos; in First BdOSN Code Sprint'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-3739419379034358224</id><published>2008-08-16T01:21:00.002+06:00</published><updated>2011-08-21T14:52:37.101+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python send email'/><title type='text'>How to send email from a Python script</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Today I needed to send email from a Python script. As always I searched Google and found the following script that fits to my need.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import smtplib&lt;br /&gt;&lt;br /&gt;SERVER = "localhost"&lt;br /&gt;&lt;br /&gt;FROM = "sender@example.com"&lt;br /&gt;TO = ["user@example.com"] # must be a list&lt;br /&gt;&lt;br /&gt;SUBJECT = "Hello!"&lt;br /&gt;&lt;br /&gt;TEXT = "This message was sent with Python's smtplib."&lt;br /&gt;&lt;br /&gt;# Prepare actual message&lt;br /&gt;&lt;br /&gt;message = """\&lt;br /&gt;From: %s&lt;br /&gt;To: %s&lt;br /&gt;Subject: %s&lt;br /&gt;&lt;br /&gt;%s&lt;br /&gt;""" % (FROM, ", ".join(TO), SUBJECT, TEXT)&lt;br /&gt;&lt;br /&gt;# Send the mail&lt;br /&gt;&lt;br /&gt;server = smtplib.SMTP(SERVER)&lt;br /&gt;server.sendmail(FROM, TO, message)&lt;br /&gt;server.quit()&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;[Source: http://effbot.org/pyfaq/how-do-i-send-mail-from-a-python-script.htm]&lt;br /&gt;&lt;br /&gt;But when I tried to run the program, I got the following error message:&lt;br /&gt;&lt;pre&gt;Traceback (most recent call last):&lt;br /&gt;File "email.py", line 1, in &lt;module&gt;&lt;br /&gt;import smtplib&lt;br /&gt;File "/usr/lib/python2.5/smtplib.py", line 46, in &lt;module&gt;&lt;br /&gt;import email.Utils&lt;br /&gt;File "/home/dsebd/email.py", line 24, in &lt;module&gt;&lt;br /&gt;server = smtplib.SMTP(SERVER)&lt;br /&gt;AttributeError: 'module' object has no attribute 'SMTP'&lt;br /&gt;&lt;/module&gt;&lt;/module&gt;&lt;/module&gt;&lt;/pre&gt;&lt;br /&gt;I got rid of the problem when I renamed the file email.py to another file!&lt;br /&gt;&lt;br /&gt;Can anyone explain the reason?&lt;br /&gt;&lt;br /&gt;Update [21 August 2011]&lt;br /&gt;If you want to use it as function you can use the following code:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;import smtplib&lt;br /&gt;&lt;br /&gt;def send_email(sender, receiver, subject, body):&lt;br /&gt;    msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s" &lt;br /&gt;        %(sender, receiver, subject, body))&lt;br /&gt;    s = smtplib.SMTP('localhost')&lt;br /&gt;    s.sendmail(sender, [receiver], msg)&lt;br /&gt;    s.quit()&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;You should also check this link for more examples (won't work in older version of python like 2.4.x): &lt;a href="http://docs.python.org/library/email-examples.html"&gt;http://docs.python.org/library/email-examples.html&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-3739419379034358224?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/3739419379034358224/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=3739419379034358224' title='10 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3739419379034358224'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3739419379034358224'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/08/how-to-send-email-from-python-script.html' title='How to send email from a Python script'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>10</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-4850592314023963251</id><published>2008-08-09T00:11:00.000+06:00</published><updated>2008-08-09T00:29:34.225+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python create thumbnail'/><category scheme='http://www.blogger.com/atom/ns#' term='Python Image resize'/><title type='text'>Create thumbnail by resizing image in Python</title><content type='html'>Sometimes we need to create thumbnails of certain size from image. In this post I show you how to create thumbnail by resizing image in Python.&lt;br /&gt;Here is the Python code for creating thumbnail / resizing an image:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-size:110%;"&gt;import Image&lt;br /&gt;&lt;br /&gt;def generate_and_save_thumbnail(imageFile, h, w, ext):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;image = Image.open(imageFile)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;image = image.resize((w, h), Image.ANTIALIAS)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;outFileLocation = "./images/"&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;outFileName = "thumb"&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;image.save(outFileLocation + outFileName + ext)&lt;br /&gt;&lt;br /&gt;# set the image file name here&lt;br /&gt;myImageFile = "myfile.jpg"&lt;br /&gt;# set the image file extension&lt;br /&gt;extension = ".jpg"&lt;br /&gt;# set height&lt;br /&gt;h = 200&lt;br /&gt;# set width&lt;br /&gt;w = 200&lt;br /&gt;&lt;br /&gt;generate_and_save_thumbnail(myImageFile, h, w, extension)&lt;br /&gt;&lt;/span&gt;  &lt;/code&gt;&lt;br /&gt;The second argument of image.resize() is the filter. You have several options there:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Image.ANTIALIAS&lt;/li&gt;&lt;li&gt;Image.BICUBIC&lt;/li&gt;&lt;li&gt;Image.BILINEAR&lt;/li&gt;&lt;li&gt;Image.NEAREST&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;Each uses different algorithm. For downsampling (reducing the size) you can use ANTIALIAS. Other filers may increase the size.&lt;br /&gt;&lt;br /&gt;You can also look at the following Python modules:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://docs.python.org/lib/module-imageop.html"&gt;imageop&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://docs.python.org/lib/module-imghdr.html"&gt;imghdr&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-4850592314023963251?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/4850592314023963251/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=4850592314023963251' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/4850592314023963251'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/4850592314023963251'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/08/create-thumbnail-by-resizing-image-in.html' title='Create thumbnail by resizing image in Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-8017798522408169937</id><published>2008-07-26T18:34:00.002+06:00</published><updated>2011-05-05T15:07:55.147+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='regular expression'/><title type='text'>Strip HTML tags using Python</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;We often need to strip HTML tags from string (or HTML source). I usually do it using a simple regular expression in Python. Here is my function to strip HTML tags:&lt;br /&gt;&lt;pre&gt;def remove_html_tags(data):&lt;br /&gt;    p = re.compile(r'&amp;lt;.*?&amp;gt;')&lt;br /&gt;    return p.sub('', data)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Here is another function to remove more than one consecutive white spaces:&lt;br /&gt;&lt;pre&gt;def remove_extra_spaces(data):&lt;br /&gt;    p = re.compile(r'\s+')&lt;br /&gt;    return p.sub(' ', data)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Note that &lt;a href="http://docs.python.org/lib/module-re.html"&gt;re module&lt;/a&gt; needs to be imported in order to use regular expression.&lt;br /&gt;&lt;br /&gt;Here you can find an updated code that gets the text from html: &lt;a href="http://love-python.blogspot.com/2011/04/html-to-text-in-python.html"&gt;http://love-python.blogspot.com/2011/04/html-to-text-in-python.html &lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-8017798522408169937?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/8017798522408169937/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=8017798522408169937' title='19 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/8017798522408169937'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/8017798522408169937'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/07/strip-html-tags-using-python.html' title='Strip HTML tags using Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>19</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-4085380023716035316</id><published>2008-07-25T01:55:00.000+06:00</published><updated>2008-07-25T02:12:33.165+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='HTTP Response Header'/><title type='text'>HTTP Response Header Information in Python</title><content type='html'>Sometimes we need to get the HTTP Response header from our program. You can check the following python code, that prints the http response header:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; import urllib2&lt;br /&gt;&gt;&gt;&gt; usock = urllib2.urlopen('http://bdosn.org')&lt;br /&gt;&gt;&gt;&gt; print usock.info()&lt;br /&gt;Date: Thu, 24 Jul 2008 19:52:53 GMT&lt;br /&gt;Server: Apache/1.3.39 (Unix) PHP/5.2.3 mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 mod_gzip/1.3.26.1a FrontPage/5.0.2.2634a mod_ssl/2.8.30 OpenSSL/0.9.7a&lt;br /&gt;X-Powered-By: PHP/5.2.3&lt;br /&gt;Connection: close&lt;br /&gt;Transfer-Encoding: chunked&lt;br /&gt;Content-Type: text/html&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt; &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;If you want to get the value of a particular item, use the get() method:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; print usock.info().get('Date')&lt;br /&gt;Thu, 24 Jul 2008 19:52:53 GMT&lt;br /&gt;&gt;&gt;&gt; &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Hope you will find this tips useful!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-4085380023716035316?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/4085380023716035316/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=4085380023716035316' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/4085380023716035316'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/4085380023716035316'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/07/http-response-header-information-in.html' title='HTTP Response Header Information in Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-7938097847667933302</id><published>2008-07-22T02:45:00.000+06:00</published><updated>2008-07-22T03:02:25.035+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python web spider'/><category scheme='http://www.blogger.com/atom/ns#' term='python web crawler'/><category scheme='http://www.blogger.com/atom/ns#' term='proxy'/><title type='text'>check status proxy address</title><content type='html'>Often we need to use proxy addresses in our web spiders / crawler. But most of the time the proxies don't work. So I made a little python program to test the proxy IPs. Let's look into the code:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import urllib2, socket&lt;br /&gt;&lt;br /&gt;socket.setdefaulttimeout(180)&lt;br /&gt;&lt;br /&gt;# read the list of proxy IPs in proxyList&lt;br /&gt;proxyList = ['125.76.226.9:80', '213.55.87.162:6588'] # there are two sample proxy ip&lt;br /&gt;&lt;br /&gt;for item in proxyList:&lt;br /&gt;    if is_bad_proxy(item):&lt;br /&gt;        print "Bad Proxy", item&lt;br /&gt;    else&lt;br /&gt;        print item, "is working"&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;def is_bad_proxy(pip):    &lt;br /&gt;    try:        &lt;br /&gt;        proxy_handler = urllib2.ProxyHandler({'http': pip})        &lt;br /&gt;        opener = urllib2.build_opener(proxy_handler)&lt;br /&gt;        opener.addheaders = [('User-agent', 'Mozilla/5.0')]&lt;br /&gt;        urllib2.install_opener(opener)        &lt;br /&gt;        req=urllib2.Request('http://www.your-domain.com')  # change the url address here&lt;br /&gt;        sock=urllib2.urlopen(req)&lt;br /&gt;    except urllib2.HTTPError, e:        &lt;br /&gt;        print 'Error code: ', e.code&lt;br /&gt;        return e.code&lt;br /&gt;    except Exception, detail:&lt;br /&gt;&lt;br /&gt;        print "ERROR:", detail&lt;br /&gt;        return 1&lt;br /&gt;    return 0&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Hope the proxy checker will be useful to you!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-7938097847667933302?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/7938097847667933302/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=7938097847667933302' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/7938097847667933302'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/7938097847667933302'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/07/check-status-proxy-address.html' title='check status proxy address'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-2303455267418688869</id><published>2008-07-19T01:00:00.000+06:00</published><updated>2008-07-19T01:24:06.683+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python web spider'/><category scheme='http://www.blogger.com/atom/ns#' term='python web crawler'/><title type='text'>Accept-Encoding 'gzip' to make your cralwer faster</title><content type='html'>If you are looking for a way to make your web crawler / spider work faster, then you must be looking for reducing the time to fetch data from the Internet. Fortunately many websites provide the content in compressed format if the server gets such type of request. If you see the request header of Firefox (you can use firebug to see the request / response headers), you can find that it always asks for gzip content. If the server provides gzip, then it sends data in gzip form otherwise it sends html. gzip data reduces bandwidth and thus make the program to scrape / harvest data faster.&lt;br /&gt;&lt;br /&gt;So you can do the same from you Python code. Just add &lt;code&gt;('Accept-Encoding', 'gzip,deflate')&lt;/code&gt; in the request header. Check the following code chunk:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;opener = urllib2.build_opener()&lt;br /&gt;opener.addheaders = [('Referer', referer),&lt;br /&gt;   ('User-Agent', uagent),&lt;br /&gt;   ('Accept-Encoding', 'gzip,deflate')]&lt;br /&gt;usock = opener.open(url)&lt;br /&gt;url = usock.geturl()&lt;br /&gt;data = decode(usock)&lt;br /&gt;usock.close()                &lt;br /&gt;return data&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Note the decode() function used in the code. Yes, you have to decode the content (if it's compressed).&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;def decode (page):&lt;br /&gt;    encoding = page.info().get("Content-Encoding")    &lt;br /&gt;    if encoding in ('gzip', 'x-gzip', 'deflate'):&lt;br /&gt;        content = page.read()&lt;br /&gt;        if encoding == 'deflate':&lt;br /&gt;            data = StringIO.StringIO(zlib.decompress(content))&lt;br /&gt;        else:&lt;br /&gt;            data = gzip.GzipFile('', 'rb', 9, StringIO.StringIO(content))&lt;br /&gt;        page = data.read()&lt;br /&gt;&lt;br /&gt;    return page&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You can also have a look at this page from the book - Dive Into Python: &lt;a href="http://diveintopython.org/http_web_services/gzip_compression.html"&gt;http://diveintopython.org/http_web_services/gzip_compression.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;If you would like to buy a hard copy of this book, get it from here: &lt;a href="http://www.amazon.com/gp/product/1590593561?ie=UTF8&amp;tag=lovpyt-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1590593561"&gt;Dive Into Python&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=lovpyt-20&amp;l=as2&amp;o=1&amp;a=1590593561" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-2303455267418688869?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/2303455267418688869/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=2303455267418688869' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2303455267418688869'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2303455267418688869'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/07/accept-encoding-gzip-to-make-your.html' title='Accept-Encoding &apos;gzip&apos; to make your cralwer faster'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-1210202267745266872</id><published>2008-07-13T15:49:00.000+06:00</published><updated>2008-07-13T16:20:08.191+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python Database Programming'/><title type='text'>Using Python to interact with MySQL</title><content type='html'>I have to use MySQL database frequently. Interacting with MySQL is easy and simple. There is a nice module named MySQLdb is available for this purpose.&lt;br /&gt;&lt;br /&gt;I am not writing details about using it as there is a good tutorial "&lt;a href="http://www.kitebird.com/articles/pydbapi.html"&gt;Writing MySQL Scripts with Python DB-API&lt;/a&gt;" available online. I myself read this when I used MySQL with Python for the first time.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.amazon.com/gp/product/059652708X?ie=UTF8&amp;tag=lovpyt-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=059652708X"&gt;MySQL Cookbook&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=lovpyt-20&amp;l=as2&amp;o=1&amp;a=059652708X" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /&gt; also covers database programming in Python and other languages as well.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-1210202267745266872?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/1210202267745266872/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=1210202267745266872' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/1210202267745266872'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/1210202267745266872'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/07/using-python-to-interact-with-mysql.html' title='Using Python to interact with MySQL'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-5189727222727643652</id><published>2008-07-05T12:18:00.000+06:00</published><updated>2008-07-05T12:23:56.712+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python web spider'/><category scheme='http://www.blogger.com/atom/ns#' term='python web crawler'/><title type='text'>Regular Expression not working in scraper?</title><content type='html'>This is a very common problem for the beginners who try to write web crawler / spider / scraper. The content is fetched but regex is not working right. :(&lt;br /&gt;&lt;br /&gt;But the problem is not with the regular expression. You just need to add the following two lines after you fetch content of a web page:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-size:120%;"&gt;content = content.replace("\n", "")&lt;br /&gt;content = content.replace("\r", "")&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Now the regex should work if everything else is ok!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-5189727222727643652?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/5189727222727643652/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=5189727222727643652' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/5189727222727643652'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/5189727222727643652'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/07/regular-expression-not-working-in.html' title='Regular Expression not working in scraper?'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-735316814219523659</id><published>2008-06-19T22:20:00.000+06:00</published><updated>2008-06-19T22:35:06.423+06:00</updated><title type='text'>Run Python program in windows command prompt</title><content type='html'>To run Python program in windows, I have downloaded and installed python windows installer from &lt;a href="http://www.python.org/download/"&gt;http://www.python.org/download/&lt;/a&gt;. IDLE is installed by default when I install the python windows installer. So python programs can be written and/or executed using IDLE. Or you can just double click a program to run it. Another way is to run from the windows command prompt. Right click on my computer. Then click &lt;span style="font-weight: bold;"&gt;Properties &gt; Advanced &gt; Environment Variables&lt;/span&gt;. Now edit the '&lt;span style="font-weight: bold;"&gt;path&lt;/span&gt;' variable. Add the location of python there (in my case it is F:\Python25). If there are more than one variables, each one should be separated by a semicolon (;). For example:&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Variable name: path&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Variable value: F:\TCWIN45\BIN;F:\Python25&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now you can run / execute a python program from windows command prompt using the following command:&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;python abc.py&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You can also get the python interpreter if you just type &lt;span style="font-weight: bold;"&gt;python &lt;/span&gt;and press enter in the command prompt.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-735316814219523659?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/735316814219523659/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=735316814219523659' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/735316814219523659'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/735316814219523659'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/06/run-yython-program-in-windows-command.html' title='Run Python program in windows command prompt'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-6597021787463297856</id><published>2008-06-05T09:17:00.000+06:00</published><updated>2008-06-05T09:24:42.013+06:00</updated><title type='text'>Function call in Python</title><content type='html'>Check the following code:&lt;br /&gt;&lt;pre&gt;&lt;span style="font-size:120%;"&gt;def fibonacci(x):   &lt;br /&gt;    if x &lt; 2: return 1&lt;br /&gt;    return (fibonacci(x-2) + fibonacci(x-1))&lt;br /&gt;   &lt;br /&gt;def factorial(x):&lt;br /&gt;    if x &lt; 2: return 1&lt;br /&gt;    return (x * factorial(x-1))&lt;br /&gt;   &lt;br /&gt;def main():      &lt;br /&gt;    funcs = [fibonacci, factorial]&lt;br /&gt;    n = 10&lt;br /&gt;    for i in range(len(funcs)):       &lt;br /&gt;        print funcs[i](n)       &lt;br /&gt;   &lt;br /&gt;main()&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Interesting part of the code is &lt;span style="font-size:120%;"&gt;&lt;code&gt;print funcs[i](n)&lt;/code&gt;&lt;/span&gt;. Sometimes it is useful to call the function in this way.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-6597021787463297856?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/6597021787463297856/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=6597021787463297856' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6597021787463297856'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6597021787463297856'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/06/function-call-in-python.html' title='Function call in Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-1814666791073140488</id><published>2008-05-26T01:13:00.000+06:00</published><updated>2008-05-26T01:24:46.671+06:00</updated><title type='text'>List of files, directories in Python</title><content type='html'>Here I present a short python program that prints the list of all files inside the current directory and subdirectories. It prints filename with relative path to the current directory.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="font-size:110%;"&gt;import os&lt;br /&gt;&lt;br /&gt;for root, dirs, files in os.walk('./'):&lt;br /&gt;   for name in files:       &lt;br /&gt;       filename = os.path.join(root, name)&lt;br /&gt;       print filename&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;You can also print the list of directories only (just print the dirs). Actually I needed this stuff to solve a problem from &lt;a href="http://treasurehunt.appspot.com/"&gt;Google treasure hunt&lt;/a&gt;. Let me know if you want me to share the full source code of the solutions of Google treasure hunt. Also share your code, if you have any different idea!&lt;br /&gt;&lt;br /&gt;Check the &lt;a href="http://docs.python.org/lib/os-file-dir.html"&gt;python documentation&lt;/a&gt; to learn more about processing Files and Directories.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-1814666791073140488?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/1814666791073140488/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=1814666791073140488' title='13 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/1814666791073140488'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/1814666791073140488'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/05/list-of-files-directories-in-python.html' title='List of files, directories in Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>13</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-2129492668510352231</id><published>2008-05-21T01:50:00.000+06:00</published><updated>2008-05-21T02:11:39.302+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='login script in python'/><title type='text'>Myspace auto login using Python</title><content type='html'>Today I am going to share with you an interesting program - a Python script that logs in to myspace given your username (email address) and password. If you study the script, you will get idea about the following things:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;HTTP POST in Python&lt;/li&gt;&lt;li&gt;How to use cookiejar&lt;/li&gt;&lt;li&gt;How to add user-agent, referer etc. to the request header using Python&lt;/li&gt;&lt;li&gt;And of course, how to auto login to a site :)&lt;/li&gt;&lt;/ul&gt;Here is the code:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="font-size:110;"&gt;import urllib2, cookielib, re&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;url = 'http://secure.myspace.com/index.cfm?fuseaction=login.process'&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;email = "" #put your email address here&lt;br /&gt;pwd = ""   #put your password here&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;data = "__VIEWSTATE=%2FwEPDwUKLTY1Mjc2MTMwMWQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgIFPWN0bDAwJGN0bDAwJE1haW4kY3BNYWluJFNwbGFzaERpc3BsYXkkY3RsMDAkUmVtZW1iZXJfQ2hlY2tib3gFPWN0bDAwJGN0bDAwJE1haW4kY3BNYWluJFNwbGFzaERpc3BsYXkkY3RsMDAkTG9naW5fSW1hZ2VCdXR0b24%3D&amp;amp;NextPage=&amp;amp;ctl00%24ctl00%24Main%24cpMain%24SplashDisplay%24ctl00%24Email_Textbox="+email+"&amp;amp;ctl00%24ctl00%24Main%24cpMain%24SplashDisplay%24ctl00%24Password_Textbox="+pwd+"&amp;amp;ctl00%24ctl00%24Main%24cpMain%24SplashDisplay%24ctl00%24Login_ImageButton.x=36&amp;amp;ctl00%24ctl00%24Main%24cpMain%24SplashDisplay%24ctl00%24Login_ImageButton.y=15&amp;amp;ctl00%24ctl00%24Main%24cpMain%24SplashDisplay%24ctl00%24nexturl=&amp;amp;ctl00%24ctl00%24Main%24cpMain%24SplashDisplay%24ctl00%24apikey=&amp;amp;ctl00%24ctl00%24Main%24cpMain%24SplashDisplay%24ctl00%24ContainerPage="&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;cj = cookielib.CookieJar()&lt;br /&gt;&lt;br /&gt;opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))&lt;br /&gt;&lt;br /&gt;opener.addheaders = [('Referer', 'http://www.myspace.com/index.cfm?fuseaction=splash'),&lt;br /&gt;&lt;br /&gt;                   ('Content-Type', 'application/x-www-form-urlencoded'),&lt;br /&gt;&lt;br /&gt;                   ('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14')]&lt;br /&gt;&lt;br /&gt;usock = opener.open(url, data)&lt;br /&gt;&lt;br /&gt;the_page = usock.read()&lt;br /&gt;&lt;br /&gt;usock.close()&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And check &lt;a style="font-weight: bold;" href="http://speed-dev.blogspot.com/2008/05/use-firebug-for-high-speed-development.html"&gt;this link&lt;/a&gt; to get idea, how do I know details about request header and post values!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-2129492668510352231?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/2129492668510352231/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=2129492668510352231' title='14 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2129492668510352231'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2129492668510352231'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/05/myspace-auto-login-using-python.html' title='Myspace auto login using Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>14</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-5491436691060457936</id><published>2008-05-19T17:20:00.001+06:00</published><updated>2008-05-19T17:28:04.977+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python for Mobile Phone'/><title type='text'>First problem I faced in PyS60</title><content type='html'>When I tried to connect to a website using Python from my mobile phone, I got into trouble. Every time I tried a simple program I got the following error message:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;IOError:[Errno socket error](0, 'getaddrinfo failed')&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Here is the code I tried:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import urllib&lt;br /&gt;&lt;br /&gt;usock = urllib.urlopen("http://example.com")&lt;br /&gt;data = usock.read()&lt;br /&gt;usock.close()&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;I tried Google but couldn't find any good solution. Then I did some trial-n-error myself and got rid of the problem!&lt;br /&gt;Actually when I connect to Internet from my mobile phone I have 3 access points - GP-WAP, GP-MMS and GP-Internet. When I browse from my mobile phone (it's Nokia N70), I use GP-WAP. So when the python program asked for the option I selected that and got the error. When I selected GP-Internet, I got rid of the problem. &lt;br /&gt;&lt;br /&gt;Now I can connect the Internet using Python from mobile!!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-5491436691060457936?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/5491436691060457936/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=5491436691060457936' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/5491436691060457936'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/5491436691060457936'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/05/first-problem-i-faced-in-pys60.html' title='First problem I faced in PyS60'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-2932245324202632503</id><published>2008-05-19T11:31:00.000+06:00</published><updated>2008-05-19T11:45:03.922+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python for Mobile Phone'/><title type='text'>py60 - Python for S60</title><content type='html'>Yes, I have started using Python in my mobile phone !!!&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;Python for S60 is Nokia's port of the Python language to the S60 smartphone platform. In addition to the standard features of the Python language, PyS60 provides access to many of the phone's uniquely smartphone-y functions, such as camera, contacts, calendar, audio recording and playing, TCP/IP and Bluetooth communications and simple telephony.&lt;/blockquote&gt; (from &lt;a href="http://wiki.opensource.nokia.com/projects/Python_for_S60"&gt;http://wiki.opensource.nokia.com/projects/Python_for_S60&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;You can use emulator or your mobile phone (S60 platform) to run/test python programs. I use my Nokia N70 to run python and so far it's great fun! You can write the program in your computer and transfer it to your mobile phone. There is an interactive console in the mobile phone so that you can write your program directly in the mobile phone. There is another blue-tooth based console which I haven't tried yet.&lt;br /&gt;&lt;br /&gt;You can download the latest version of pyS60 from &lt;a href="http://sourceforge.net/projects/pys60/"&gt;sourceforge&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;And I am using &lt;a href="http://www.mobilenin.com/pys60/menu.htm"&gt;this tutorial&lt;/a&gt; in my py60 adventure.&lt;br /&gt;&lt;br /&gt;Let me know about your experience if you are using py60/pyS60.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-2932245324202632503?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/2932245324202632503/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=2932245324202632503' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2932245324202632503'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2932245324202632503'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/05/py60-python-for-s60.html' title='py60 - Python for S60'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-839773960401487349</id><published>2008-05-11T23:26:00.000+06:00</published><updated>2008-05-12T00:01:27.058+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='CSV write in Python'/><title type='text'>Common problem in CSV file writing</title><content type='html'>First let me tell you how I write CSV files :)&lt;br /&gt;I don't use Pythons CSV module for writing. I just name the file xyz.csv (fp = open('xzy.csv', 'w')) and write using something like: fp.write(a+','+b+','+c)&lt;br /&gt;&lt;br /&gt;But sometimes it can create a problem if any string contains a comma (,) within itself. For example if the string a is 'hello, how are you?', then it will be printed in two columns... so before writing to file I use:&lt;br /&gt;a = a.replace(',', ' ')&lt;br /&gt;&lt;br /&gt;Is there any other way to avoid such situation? If you know, please share.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-839773960401487349?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/839773960401487349/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=839773960401487349' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/839773960401487349'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/839773960401487349'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/05/common-problem-in-csv-file-writing.html' title='Common problem in CSV file writing'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-6345552790188317451</id><published>2008-05-11T01:01:00.000+06:00</published><updated>2008-05-11T02:56:46.773+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python hex to ASCII'/><title type='text'>Convert hex to ASCII string in Python</title><content type='html'>Sometimes web pages use hexadecimal values of of ASCII characters. To parse them we need to convert them to ASCII string first. Today I faced a similar problem and came up with the following solution:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="font-size:120%;"&gt;import binascii, re&lt;br /&gt;&lt;br /&gt;def asciirepl(match):&lt;br /&gt;  # replace the hexadecimal characters with ascii characters&lt;br /&gt;  s = match.group()  &lt;br /&gt;  return binascii.unhexlify(s)  &lt;br /&gt;&lt;br /&gt;def reformat_content(data):&lt;br /&gt;  p = re.compile(r'\\x(\w{2})')&lt;br /&gt;  return p.sub(asciirepl, data)&lt;br /&gt;&lt;br /&gt;hex_string = '\x70f=l\x26hl=en\x26geocode=\x26q\x3c'&lt;br /&gt;ascii_string = reformat_content(hex_string)&lt;br /&gt;&lt;br /&gt;print ascii_string&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I took help of &lt;a href="http://docs.python.org/lib/module-binascii.html"&gt;binascii&lt;/a&gt; module (and of course the &lt;a href="http://docs.python.org/lib/module-re.html"&gt;re&lt;/a&gt; module). The logic was simple, I just replaced \x.. (here .. represents two characters) with their corresponding ASCII characters.&lt;br /&gt;&lt;br /&gt;You can check my other post to convert ASCII values to ASCII characters: &lt;a href="http://love-python.blogspot.com/2008/04/get-ascii-string-for-decimal-number-in.html"&gt;http://love-python.blogspot.com/2008/04/get-ascii-string-for-decimal-number-in.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;And please share if you have any other idea.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-6345552790188317451?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/6345552790188317451/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=6345552790188317451' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6345552790188317451'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6345552790188317451'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/05/convert-hext-to-ascii-string-in-python.html' title='Convert hex to ASCII string in Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-3045228381780125217</id><published>2008-05-09T23:31:00.000+06:00</published><updated>2008-05-09T23:44:45.230+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python localtime'/><title type='text'>generate different file name each time you run a program</title><content type='html'>I have written a script today which has an interesting behavior. Each time the program runs, it generates output in a different file (or in other word, the file name has to be different each time the program runs). So I decided to use current time as the prefix of the filename. I used the localtime() function of &lt;a href="http://docs.python.org/lib/module-time.html"&gt;time module&lt;/a&gt; in Python.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-size:120%;"&gt;&gt;&gt;&gt; import time&lt;br /&gt;&gt;&gt;&gt; time.localtime()&lt;br /&gt;(2008, 5, 9, 23, 32, 8, 4, 130, 0)&lt;br /&gt;&gt;&gt;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;I made a string from localtime and added it before the filename. You can get the idea from the following code block. It's so simple!&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="font-size:120%;"&gt;import time&lt;br /&gt;&lt;br /&gt;prefix = ''&lt;br /&gt;for t in time.localtime():&lt;br /&gt;  prefix += t.__str__()&lt;br /&gt;&lt;br /&gt;fileName = prefix + "_result.csv"&lt;br /&gt;&lt;br /&gt;print fileName&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Keep enjoying Python!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-3045228381780125217?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/3045228381780125217/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=3045228381780125217' title='10 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3045228381780125217'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3045228381780125217'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/05/generate-different-file-name-each-time.html' title='generate different file name each time you run a program'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>10</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-8772978555565820999</id><published>2008-05-07T09:44:00.000+06:00</published><updated>2008-05-07T09:53:51.134+06:00</updated><title type='text'>getpass - Python module for portable password input</title><content type='html'>Last night I found an interesting Python module, &lt;span style="font-weight: bold;"&gt;getpass&lt;/span&gt;. It has two functions:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;getpass&lt;/span&gt;():    Prompt the user for a password without echoing.&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;getuser&lt;/span&gt;():    Return the login name of the user.&lt;/li&gt;&lt;/ul&gt;The getpass function was really useful for me. But sometimes you would want to avoid the getuser function, and provide user name on your own.&lt;br /&gt;&lt;br /&gt;Please check the Python documentation for details: &lt;a href="http://docs.python.org/lib/module-getpass.html"&gt;http://docs.python.org/lib/module-getpass.html&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-8772978555565820999?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/8772978555565820999/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=8772978555565820999' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/8772978555565820999'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/8772978555565820999'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/05/getpass-python-module-for-portable.html' title='getpass - Python module for portable password input'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-5511830732041728634</id><published>2008-04-29T22:25:00.000+06:00</published><updated>2008-04-29T23:46:21.869+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASCII Code'/><title type='text'>Convert text to ASCII and ASCII to text - Python code</title><content type='html'>Python has a very simple way to convert text to ASCII and ASCII to text.&lt;br /&gt;&lt;br /&gt;To find the ASCII value of a character use the ord() function.&lt;br /&gt;Example:&lt;br /&gt;&gt;&gt;&gt; ord('B')&lt;br /&gt;66&lt;br /&gt;&lt;br /&gt;To get a character from it's ASCII value use the chr() function.&lt;br /&gt;Example:&lt;br /&gt;&gt;&gt;&gt; chr(65)&lt;br /&gt;'A'&lt;br /&gt;&lt;br /&gt;Here is a program to get the list of all characters along with their values:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="font-size:120%;"&gt;# program to print the list of characters and their ASCII values&lt;br /&gt;for value in range(0, 255):&lt;br /&gt;   print "ASCII Value:", value, "\t", "Character:", chr(value), "\n"&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Here is another simple ASCII encoding-decoding program:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="font-size:120%;"&gt;# Convertion from text to ASCII codes&lt;br /&gt;&lt;br /&gt;message = raw_input("Enter message to encode: ")&lt;br /&gt;&lt;br /&gt;print "Decoded string (in ASCII):"&lt;br /&gt;for ch in message:&lt;br /&gt;   print ord(ch),&lt;br /&gt;print "\n\n"&lt;br /&gt;&lt;br /&gt;# Convertion from ASCII codes to text&lt;br /&gt;&lt;br /&gt;message = raw_input("Enter ASCII codes: ")&lt;br /&gt;&lt;br /&gt;decodedMessage = ""&lt;br /&gt;&lt;br /&gt;for item in message.split():&lt;br /&gt;   decodedMessage += chr(int(item))   &lt;br /&gt;&lt;br /&gt;print "Decoded message:", decodedMessage&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Hope you got a clear understanding of how to convert between text and ASCII code.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-5511830732041728634?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/5511830732041728634/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=5511830732041728634' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/5511830732041728634'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/5511830732041728634'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/04/convert-text-to-ascii-and-ascii-to-text.html' title='Convert text to ASCII and ASCII to text - Python code'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-8855406355345284604</id><published>2008-04-29T01:41:00.000+06:00</published><updated>2008-04-29T01:56:02.171+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python hypertext preprocessor'/><category scheme='http://www.blogger.com/atom/ns#' term='python'/><category scheme='http://www.blogger.com/atom/ns#' term='pyhp'/><title type='text'>PyHP - Python Hypertext Preprocessor</title><content type='html'>Couple of months ago, I was trying to embed Python code into HTML. After given the problem to solve, I was planning for a solution and looking into Python libraries. Suddenly I thought, why not spend some time in google to see if there already exists something similar. Actually I was looking for something very simple and I got one!!! It's called PyHP - Python Hypertext Preprocessor. Thank God, I didn't have to reinvent the wheel, as it was almost the similar thing what I was thinking to build. It's a small, fast, hypertext preprocessor in my favorite language - Python. And of course it is open source. The only thing I needed to change in the code is, I made the code to print output in a html file rather than in console. It was just a simple tweak.&lt;br /&gt;&lt;br /&gt;Download and play with &lt;a href="http://www.ccraig.org/software/pyhp/"&gt;PyHP - Python Hypertext Preprocessor&lt;/a&gt;. You can use it as a standalone program, or use it with Apache's mod-python.&lt;br /&gt;&lt;br /&gt;Enjoy Programming, Enjoy Python!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-8855406355345284604?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/8855406355345284604/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=8855406355345284604' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/8855406355345284604'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/8855406355345284604'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/04/pyhp-python-hypertext-preprocessor.html' title='PyHP - Python Hypertext Preprocessor'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-1211805057477576083</id><published>2008-04-24T21:10:00.000+06:00</published><updated>2008-04-24T21:18:32.422+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python list copy'/><title type='text'>Copy Compound object lists using deepcopy</title><content type='html'>Sometimes you might get into trouble while copying a compound object list to another in Python. If this is so, then you should use the copy module of Python. To know details about shallow and deep copy operations in Python please visit &lt;a href="http://docs.python.org/lib/module-copy.html"&gt;http://docs.python.org/lib/module-copy.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;To copy simple lists without using copy module of python, you can use the method described in another post of my blog &lt;a href="http://love-python.blogspot.com/2008/04/how-to-copy-list-in-python.html"&gt;http://love-python.blogspot.com/2008/04/how-to-copy-list-in-python.html&lt;/a&gt;&lt;br /&gt;One of my friend found that this method wasn't working for him while copying a graph into another (he used adjacency matrix to represent graph), then he tried deepcopy and got rid of the problem.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-1211805057477576083?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/1211805057477576083/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=1211805057477576083' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/1211805057477576083'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/1211805057477576083'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/04/copy-compound-object-lists-using.html' title='Copy Compound object lists using deepcopy'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-7629511462951214662</id><published>2008-04-20T14:34:00.000+06:00</published><updated>2008-04-20T14:39:52.398+06:00</updated><title type='text'>Locate Firefox Cache - Python Code</title><content type='html'>Here I share my python code to locate firefox cache directory.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;/code&gt;&lt;pre&gt;&lt;br /&gt;# program to locate firefox cache directory in Linux&lt;br /&gt;from subprocess import Popen, PIPE&lt;br /&gt;&lt;br /&gt;name = raw_input('Enter the top-level direcotry ( example: /home ): ')&lt;br /&gt;&lt;br /&gt;li = Popen(['find', name, '-iname', 'cache'], stdout=PIPE).stdout.read().split('\n')&lt;br /&gt;&lt;br /&gt;flag = 1&lt;br /&gt;&lt;br /&gt;for item in li:&lt;br /&gt;   if item.find('firefox') != -1:&lt;br /&gt;       print 'Cache Directory: ', item&lt;br /&gt;       flag = 0&lt;br /&gt;       break&lt;br /&gt;      &lt;br /&gt;if flag:&lt;br /&gt;   for item in li:&lt;br /&gt;       if item.find('mozilla') != -1:&lt;br /&gt;           print 'Cache Directory: ', item&lt;br /&gt;           break&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;It will work on Linux (*nix). To use it in windows with minimum modification, you need to install UnxUtil in your machine. Please visit &lt;a href="http://speed-dev.blogspot.com/2008/03/unxutil-run-unix-linux-command-in.html"&gt;http://speed-dev.blogspot.com/2008/03/unxutil-run-unix-linux-command-in.html&lt;/a&gt; to know more about UnxUtil.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-7629511462951214662?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/7629511462951214662/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=7629511462951214662' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/7629511462951214662'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/7629511462951214662'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/04/locate-firefox-cache-python-code.html' title='Locate Firefox Cache - Python Code'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-4809962996942233646</id><published>2008-04-19T22:35:00.000+06:00</published><updated>2008-04-19T22:42:53.493+06:00</updated><title type='text'>Adjacency Matrix (Graph) in Python</title><content type='html'>Adjacency matrix is a widely used graph data structure used to store graph. Couple of days ago I had to write a Python code that reads user input from console and stores the graph in an adjacency matrix. I used List for this purpose. Here is my code:-&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;def graph_input():&lt;br /&gt;    V = int(raw_input("Enter the number of Nodes: "))&lt;br /&gt;    E = int(raw_input("Enter the number of Edges: "))&lt;br /&gt;&lt;br /&gt;    print "Enter Edges with weights:\n"&lt;br /&gt;&lt;br /&gt;    adj_matrix = []&lt;br /&gt; # vertex numbering starts from 0&lt;br /&gt;    for i in range(0, V):&lt;br /&gt;        temp = []&lt;br /&gt;        for j in range(0, V):&lt;br /&gt;            temp.append(0)&lt;br /&gt;        adj_matrix.append(temp)&lt;br /&gt;    &lt;br /&gt;    for i in range(0, E):&lt;br /&gt;        s = raw_input()&lt;br /&gt;        u, v, w = s.split()&lt;br /&gt;        u = int(u)&lt;br /&gt;        v = int(v)&lt;br /&gt;        w = int(w)&lt;br /&gt;        adj_matrix[v][u] = adj_matrix[u][v] = w&lt;br /&gt;&lt;br /&gt; # print the adjacency matrix&lt;br /&gt;    for i in range (0, V):&lt;br /&gt;        print adj_matrix[i]&lt;br /&gt;&lt;br /&gt;    return adj_matrix&lt;br /&gt;&lt;br /&gt;graph = graph_input()&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Let me know if you have any other idea to represent a graph using adjacency matrix in Python.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-4809962996942233646?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/4809962996942233646/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=4809962996942233646' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/4809962996942233646'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/4809962996942233646'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/04/adjacency-matrix-graph-in-python.html' title='Adjacency Matrix (Graph) in Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-5997715043051560101</id><published>2008-04-18T23:04:00.000+06:00</published><updated>2008-04-18T23:18:03.657+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python web frameworks'/><title type='text'>Python Web Frameworks - A Short List</title><content type='html'>Python is heavily used for web application development. Web frameworks make your life easier while developing a web application - doesn't matter it's small, medium or huge. Here I give a short list of popular python web frameworks:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a style="font-weight: bold;" href="http://www.djangoproject.com/"&gt;Django&lt;/a&gt; - Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;a style="font-weight: bold;" href="http://pylonshq.com/"&gt;Pylons&lt;/a&gt; - Pylons is a lightweight web framework emphasizing flexibility and rapid development.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;a style="font-weight: bold;" href="http://www.turbogears.org/"&gt;TurboGears&lt;/a&gt; - the rapid Web development megaframework&lt;a href="http://webpy.org/"&gt;&lt;br /&gt;&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://webpy.org/"&gt;&lt;span style="font-weight: bold;"&gt;web.py&lt;/span&gt;&lt;/a&gt; - web.py is a web framework for python that is as simple as it is powerful.&lt;/li&gt;&lt;/ul&gt;I have little idea about Pylons. But haven't looked at other python web frameworks. So I am not going for any comparison among the python web frameworks :-)&lt;br /&gt;&lt;br /&gt;For a more detail list of python web framework please visit here: &lt;a href="http://wiki.python.org/moin/WebFrameworks"&gt;http://wiki.python.org/moin/WebFrameworks&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-5997715043051560101?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/5997715043051560101/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=5997715043051560101' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/5997715043051560101'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/5997715043051560101'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/04/python-web-frameworks-short-list.html' title='Python Web Frameworks - A Short List'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-1292012215511143227</id><published>2008-04-16T09:51:00.000+06:00</published><updated>2008-04-16T10:14:50.652+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python web spider'/><category scheme='http://www.blogger.com/atom/ns#' term='python web crawler'/><category scheme='http://www.blogger.com/atom/ns#' term='HTTP POST'/><title type='text'>get content (html source) of an URL by HTTP POST method in Python</title><content type='html'>To retrieve or get content (html source) of an URL, sometimes we need to POST some values. Here I show you a sample python code that uses POST.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import urllib, urllib2, time&lt;br /&gt;&lt;br /&gt;url = 'http://www.example.com' # write ur URL here&lt;br /&gt;&lt;br /&gt;values = {'key1' : 'value1', #write ur specific key/value pair&lt;br /&gt;          'key2' : 'value2',&lt;br /&gt;          'key3' : 'value3',&lt;br /&gt;          }&lt;br /&gt;&lt;br /&gt;try:&lt;br /&gt;    data = urllib.urlencode(values)          &lt;br /&gt;    req = urllib2.Request(url, data)&lt;br /&gt;    response = urllib2.urlopen(req)&lt;br /&gt;    the_page = response.read() &lt;br /&gt;    print the_page &lt;br /&gt;except Exception, detail: &lt;br /&gt;    print "Err ", detail &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Hope it will be useful for you while writing web crawler/spider, specially where values must be submitted using HTTP POST method to get or extract content from an URL.&lt;br /&gt;&lt;br /&gt;Please write your comments.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-1292012215511143227?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/1292012215511143227/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=1292012215511143227' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/1292012215511143227'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/1292012215511143227'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/04/get-content-html-source-of-url-by-http.html' title='get content (html source) of an URL by HTTP POST method in Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-143197776321579598</id><published>2008-04-10T07:13:00.000+06:00</published><updated>2008-04-10T07:21:54.203+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python web spider'/><category scheme='http://www.blogger.com/atom/ns#' term='python web crawler'/><category scheme='http://www.blogger.com/atom/ns#' term='email address scraper'/><title type='text'>Python code to scrape email address using regular expression</title><content type='html'>Programmers when learn writing web spiders or crawlers, try to write a script to parse/collect email address from website. Here I post a class in Python that can harvest email address. It uses regular expression.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import re&lt;br /&gt;&lt;br /&gt;class EmailScraper():&lt;br /&gt;    def __init__(self):        &lt;br /&gt;        self.emails = []&lt;br /&gt;&lt;br /&gt;    def reset(self):&lt;br /&gt;        self.emails = []&lt;br /&gt;&lt;br /&gt;    def collectAllEmail(self, htmlSource):&lt;br /&gt;        "collects all possible email addresses from a string, but still it can miss some addresses"&lt;br /&gt;        #example: t.s@d.com&lt;br /&gt;        email_pattern = re.compile("[-a-zA-Z0-9._]+@[-a-zA-Z0-9_]+.[a-zA-Z0-9_.]+")&lt;br /&gt;        self.emails = re.findall(email_pattern, htmlSource)&lt;br /&gt;        &lt;br /&gt;    def collectEmail(self, htmlSource):&lt;br /&gt;        "collects all emails that starts with mailto: in the html source string"&lt;br /&gt;        #example: &amp;lt;a href="mailto:t.s@d.com"&amp;gt;&lt;br /&gt;        email_pattern = re.compile("&amp;lt;a\s+href=\"mailto:([a-zA-Z0-9._@]*)\"&amp;gt;", re.IGNORECASE)&lt;br /&gt;        self.emails = re.findall(email_pattern, htmlSource)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Note that it's not a bullet proof program and don't use it for any bad purpose ;)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-143197776321579598?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/143197776321579598/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=143197776321579598' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/143197776321579598'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/143197776321579598'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/04/python-code-to-scrape-email-address.html' title='Python code to scrape email address using regular expression'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-8610343651688742300</id><published>2008-04-08T08:17:00.000+06:00</published><updated>2008-04-08T08:27:18.288+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='read firefox cache'/><title type='text'>Read FireFox Cache with Python</title><content type='html'>Do you know the easiest way to view the disk cache data of your firefox browser? Just paste "about:cache?device=disk" (without the quotes) in the address bar of your firefox browser. If you see it for the first time, you will be amazed.&lt;br /&gt;&lt;br /&gt;Anyway, I had to write a program that does similar thing (locate and read firefox cache and show cache data) in Python. First I tried to automate the about:cache mechanism, but couldn't make it. Later I went for processing raw cache data.&lt;br /&gt;&lt;br /&gt;In the Cache directory, the files _CACHE_001_, _CACHE_002_, and _CACHE_003_ contain a mix of data  and metadata. The metadata contains information such as the URL requested, timestamps, size, and other details. You can view the files (I used VI in my Ubuntu to view those).&lt;br /&gt; &lt;br /&gt;The file structure of each _CACHE_00n file is as follows: &lt;br /&gt;&lt;pre&gt;&lt;br /&gt; ______________________________&lt;br /&gt;|                              |&lt;br /&gt;|       4096 byte free         |&lt;br /&gt;|        block bit-map         |&lt;br /&gt;|------------------------------|&lt;br /&gt;|                              |&lt;br /&gt;|            Blocks            |&lt;br /&gt;|             ...              |&lt;br /&gt;|                              |&lt;br /&gt;|                              |&lt;br /&gt;|______________________________|&lt;br /&gt;The size of each block varies depending on the file. &lt;br /&gt;_CACHE_001_          256 byte blocks&lt;br /&gt;_CACHE_002_         1024 byte blocks&lt;br /&gt;_CACHE_003_         4096 byte blocks&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Data in the cache is always encoded in a group of 1-4 blocks and always starts exactly on a block boundary (an exact multiple of 256, 1024, or 4096 bytes). For cache data that corresponds to metadata, it is encoded in this very specific data format. &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;      _________________&lt;br /&gt;0-3  |       magic      |    unsigned int   (0x00010008)   (Big Endian)&lt;br /&gt;     |------------------| &lt;br /&gt;4-7  |    location      |    unsigned int  (Big Endian)&lt;br /&gt;     |------------------|&lt;br /&gt;8-11 |    fetchcount    |    unsigned int  (Big Endian)&lt;br /&gt;     |------------------|&lt;br /&gt;12-15|    fetchtime     |    unsigned int  (Big Endian)&lt;br /&gt;     |------------------|&lt;br /&gt;16-19|    modifytime    |    unsigned int  (Big Endian)&lt;br /&gt;     |------------------|&lt;br /&gt;20-23|    expiretime    |    unsigned int  (Big Endian)&lt;br /&gt;     |------------------|&lt;br /&gt;24-27|    datasize      |    unsigned int  (Big Endian)&lt;br /&gt;     |------------------|&lt;br /&gt;28-31|    requestsize   |    unsigned int  (Big Endian)&lt;br /&gt;     |------------------|&lt;br /&gt;32-35|    infosize      |    unsigned int  (Big Endian)&lt;br /&gt;     |------------------|&lt;br /&gt;36-  |  request string  |    char[].  Length is determined by&lt;br /&gt;     |                  |    the value of the requestsize field&lt;br /&gt;     |       ...        |    above.  Terminated by a \x00 byte.&lt;br /&gt;     |                  |&lt;br /&gt;     |                  |&lt;br /&gt;     |------------------|&lt;br /&gt;n-   |   info string    |    char[].  Length is determined by&lt;br /&gt;     |                  |    the value of the infosize field&lt;br /&gt;     |       ...        |    above. &lt;br /&gt;     |                  |&lt;br /&gt;     |                  |&lt;br /&gt;     |                  |&lt;br /&gt;     |__________________|&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;But interestingly I didn't need to use all these knowledge. Just used regular expression to parse the data :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-8610343651688742300?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/8610343651688742300/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=8610343651688742300' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/8610343651688742300'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/8610343651688742300'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/04/read-firefox-cache-with-python.html' title='Read FireFox Cache with Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-1132692157001200851</id><published>2008-04-06T00:12:00.001+06:00</published><updated>2008-04-06T00:21:31.959+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python list copy'/><title type='text'>How to copy a list in Python?</title><content type='html'>Let me tell about a common mistake many python beginners do while trying to copy a list to another list. Suppose to copy a list listA to listB, they use &lt;span style="font-size:120%;"&gt;&lt;code&gt;listB = listA&lt;/code&gt;&lt;/span&gt;, now if you change something in one list, the other list is changed automatically as they refer to same list - actually listB points to listA! So the proper way should be&lt;br /&gt;&lt;span style="font-size:120%;"&gt;&lt;code&gt;listB = []&lt;br /&gt;listB.extend(listA)&lt;/code&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Here I paste some experiments I made:&lt;br /&gt;&lt;code&gt;&lt;span style="font-size:120%;"&gt;&gt;&gt;&gt; listA = [1, 2, 3, 4, 5]&lt;br /&gt;&gt;&gt;&gt; listB = listA&lt;br /&gt;&gt;&gt;&gt; listC = []&lt;br /&gt;&gt;&gt;&gt; listC.extend(listA)&lt;br /&gt;&gt;&gt;&gt; listB&lt;br /&gt;[1, 2, 3, 4, 5]&lt;br /&gt;&gt;&gt;&gt; listC&lt;br /&gt;[1, 2, 3, 4, 5]&lt;br /&gt;&gt;&gt;&gt; listA&lt;br /&gt;[1, 2, 3, 4, 5]&lt;br /&gt;&gt;&gt;&gt; listB[4] = 0&lt;br /&gt;&gt;&gt;&gt; listB&lt;br /&gt;[1, 2, 3, 4, 0]&lt;br /&gt;&gt;&gt;&gt; listA&lt;br /&gt;[1, 2, 3, 4, 0]&lt;br /&gt;&gt;&gt;&gt; listC&lt;br /&gt;[1, 2, 3, 4, 5]&lt;br /&gt;&gt;&gt;&gt; listC[4] = 10&lt;br /&gt;&gt;&gt;&gt; listC&lt;br /&gt;[1, 2, 3, 4, 10]&lt;br /&gt;&gt;&gt;&gt; listA&lt;br /&gt;[1, 2, 3, 4, 0]&lt;br /&gt;&gt;&gt;&gt; listB&lt;br /&gt;[1, 2, 3, 4, 0]&lt;br /&gt;&gt;&gt;&gt;&lt;/span&gt; &lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Hope you get the point!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-1132692157001200851?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/1132692157001200851/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=1132692157001200851' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/1132692157001200851'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/1132692157001200851'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/04/how-to-copy-list-in-python.html' title='How to copy a list in Python?'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-5745481743632561630</id><published>2008-04-05T02:45:00.000+06:00</published><updated>2008-04-05T02:59:13.776+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python reformat string data'/><title type='text'>Get the ASCII string for Decimal number in your data - reformat with Python</title><content type='html'>Once while writing a spider for a site, I came across some data that were not ASCII, rather had the ASCII value in the format '&amp;amp;#123' ... so I wrote a function myself to reformat the data (replace those with their corresponding ASCII values). But I had a feel that it was not Pythonic. So I searched Google, and found the following function that does the same task in a Pythonic way. Unfortunately I forgot from where I got it :(&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;span style="font-size:120%;"&gt;def asciirepl(self, match):&lt;br /&gt;   "Return the ascii string for a decimal number"&lt;br /&gt;   s = match.group()&lt;br /&gt;   value = int(s[2:-1])&lt;br /&gt;   if value &gt; 255:&lt;br /&gt;       return ''&lt;br /&gt;   return chr(value)   &lt;br /&gt;&lt;br /&gt;def reformat_content(self, data):&lt;br /&gt;   p = re.compile(r'&amp;amp;#(\d+);')&lt;br /&gt;   return p.sub(self.asciirepl, data)&lt;/span&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-5745481743632561630?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/5745481743632561630/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=5745481743632561630' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/5745481743632561630'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/5745481743632561630'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/04/get-ascii-string-for-decimal-number-in.html' title='Get the ASCII string for Decimal number in your data - reformat with Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-6612002470995023927</id><published>2008-04-03T07:40:00.000+06:00</published><updated>2008-04-03T07:51:43.349+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python Free eBook'/><title type='text'>How to think like a (Python) programmer - Free eBook</title><content type='html'>I just found this book couple of days ago. Though it won't be very useful for me to learn Python (as I already familiar with Python), I think it's an excellent book for Python newbies even with no prior programming experience. It can also be used for teaching a one semester programming course - the author wrote the book for this purpose!&lt;br /&gt;&lt;br /&gt;The book is divided into 19 chapters that covers programming fundamentals, python fundamentals, python data structures, object oriented programming, and the last chapter introduces to GUI programming with Python (Tkinter).&lt;br /&gt;&lt;br /&gt;The book is released under the GNU Free Documentation License!&lt;br /&gt;&lt;br /&gt;You can get the it from &lt;a href="http://www.greenteapress.com/thinkpython/"&gt;here&lt;/a&gt;. Download is free!&lt;br /&gt;&lt;br /&gt;Post your comments on the book.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-6612002470995023927?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/6612002470995023927/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=6612002470995023927' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6612002470995023927'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6612002470995023927'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/04/how-to-think-like-python-programmer.html' title='How to think like a (Python) programmer - Free eBook'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-3337038535369931883</id><published>2008-03-28T23:10:00.000+06:00</published><updated>2008-03-28T23:34:21.106+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Leap Year'/><title type='text'>Leap Year in Python</title><content type='html'>Year 2008 is a leap year. The leap year thing is always interesting. Sometimes I also think about the unfortunate people who have birthday on 29th February! :)&lt;br /&gt;&lt;br /&gt;Let me write two modules that determines whether a year is leap year or not, (I also write test module for this).&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-size:120%;"&gt;&lt;br /&gt;def is_leap_year2(year):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if year % 400 == 0:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return True&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;elif year % 100 == 0:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return False&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;elif year % 4 == 0:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return True&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return False&lt;br /&gt;&lt;br /&gt;def is_leap_year(year):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if year % 100 != 0 and year % 4 == 0:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return True&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;elif year % 100 == 0 and year % 400 == 0:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return True&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return False&lt;br /&gt;&lt;br /&gt;def test_is_leap_year():&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;years = [1900, 2000, 2001, 2002, 2020, 2008, 2010]&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for year in years:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if is_leap_year2(year):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print year, "is leap year"&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print year, "is not a leap year"&lt;br /&gt;&lt;br /&gt;#program starts from here&lt;br /&gt;test_is_leap_year()&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;After writing the code I found a nice discussion in python google group. Click &lt;a href="http://mail.python.org/pipermail/tutor/2003-January/019974.html"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;You can also take a look at the &lt;a href="http://en.wikipedia.org/wiki/Leap_year"&gt;wikipedia article on leap year&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-3337038535369931883?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/3337038535369931883/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=3337038535369931883' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3337038535369931883'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3337038535369931883'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/03/leap-year-in-python.html' title='Leap Year in Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-159240500998454928</id><published>2008-03-23T22:55:00.000+06:00</published><updated>2008-03-23T23:15:00.018+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Beautiful Soup'/><title type='text'>Use Beautiful Soup for screen scraping in Python</title><content type='html'>Tired of writing web spiders/crawler/scrapers? You can try Beautiful Soup in Python. I also have decided to use it in my next spiders.&lt;br /&gt;&lt;br /&gt;From their &lt;a href="http://www.crummy.com/software/BeautifulSoup/"&gt;website&lt;/a&gt;:&lt;br /&gt;&lt;blockquote&gt;Beautiful Soup is a Python HTML/XML parser designed for quick turnaround projects like screen-scraping. Three features make it powerful:&lt;br /&gt;&lt;br /&gt;   1. Beautiful Soup won't choke if you give it bad markup. It yields a parse tree that makes approximately as much sense as your original document. This is usually good enough to collect the data you need and run away.&lt;br /&gt;   2. Beautiful Soup provides a few simple methods and Pythonic idioms for navigating, searching, and modifying a parse tree: a toolkit for dissecting a document and extracting what you need. You don't have to create a custom parser for each application.&lt;br /&gt;   3. Beautiful Soup automatically converts incoming documents to Unicode and outgoing documents to UTF-8. You don't have to think about encodings, unless the document doesn't specify an encoding and Beautiful Soup can't auto detect one. Then you just have to specify the original encoding. &lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;The reasons I have decided to learn it:&lt;br /&gt;1. It will be fun to learn a new style for my web spiders&lt;br /&gt;2. It can be used to parse both HTML and XML&lt;br /&gt;3. Sometimes it in buyer's requirement that "Beautiful Soup" should be used in the Python spider&lt;br /&gt;&lt;br /&gt;You can download it from here: &lt;a href="http://www.crummy.com/software/BeautifulSoup/"&gt;http://www.crummy.com/software/BeautifulSoup/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Ruby programmers can enjoy &lt;a href="http://www.crummy.com/software/RubyfulSoup/"&gt;Rubyful Soup&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Hope the soup will help you to have a better scraping experience (for me too) :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-159240500998454928?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/159240500998454928/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=159240500998454928' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/159240500998454928'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/159240500998454928'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/03/use-beautiful-soup-for-screen-scraping.html' title='Use Beautiful Soup for screen scraping in Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-3346428943017351593</id><published>2008-03-17T21:48:00.000+06:00</published><updated>2008-03-26T00:27:01.773+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='web crawler'/><category scheme='http://www.blogger.com/atom/ns#' term='proxy'/><title type='text'>Use Proxy in your Spider</title><content type='html'>Using proxy, you can minimize the chance of getting blocked for your crawlers/spiders. Now let me tell you how to use proxy ip address in your spider in python. First load the list from a file:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-size:120%;"&gt;fileproxylist = open('proxylist.txt', 'r')&lt;br /&gt;proxyList = fileproxylist.readlines()&lt;br /&gt;indexproxy = 0&lt;br /&gt;totalproxy = len(proxyList)&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;Now for each proxy in list, call the following function:&lt;br /&gt;&lt;code&gt;&lt;span style="font-size:120%;"&gt;&lt;br /&gt;def get_source_html_proxy(url, pip):&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;proxy_handler = urllib2.ProxyHandler({'http': pip})&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;opener = urllib2.build_opener(proxy_handler)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;opener.addheaders = [('User-agent', 'Mozilla/5.0')]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;urllib2.install_opener(opener)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;req=urllib2.Request(url)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sock=urllib2.urlopen(req)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;data = sock.read()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return data&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;Hope your spidering experience will be better with proxies :-)&lt;br /&gt;&lt;br /&gt;Let me know about any alternate idea.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-3346428943017351593?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/3346428943017351593/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=3346428943017351593' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3346428943017351593'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3346428943017351593'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/03/use-proxy-in-your-spider.html' title='Use Proxy in your Spider'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-2607361681013805805</id><published>2008-03-14T22:19:00.000+06:00</published><updated>2008-03-26T00:31:18.884+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python IDE'/><title type='text'>Install IDLE in Linux</title><content type='html'>IDLE is a very nice and common tool for python programming. In windows, it comes with default python installation. But in Linux it doesn't come built in. So in Ubuntu I used Synaptic Package Manager to download/install IDLE. Fedora systems comes with Python but dont come with IDLE.. In fact if you search for a package or rpm named idle, you wont find that. IDLE is in python-tools package. So the following command (as root) will install IDLE in Fedora or other RedHat systems.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;yum install python-tools&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To download Python: &lt;a href="http://python.org/download/"&gt;http://python.org/download/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Enjoy your ride on Python !&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-2607361681013805805?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/2607361681013805805/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=2607361681013805805' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2607361681013805805'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2607361681013805805'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/03/install-idle-in-linux.html' title='Install IDLE in Linux'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-2613425679255337842</id><published>2008-03-07T22:19:00.000+06:00</published><updated>2008-03-07T22:28:45.929+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='background process'/><category scheme='http://www.blogger.com/atom/ns#' term='python'/><category scheme='http://www.blogger.com/atom/ns#' term='nohup'/><title type='text'>run python script as a background process in linux</title><content type='html'>So, you have a server to which you connect remotely, upload a python script and want to run it and logout from the server keeping the program running. If you frequently work with spiders, you surely want to do it. But how to do it? For example if your script's name is script.py, then the command is:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;nohup python script.py &amp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;And sometimes you may be interested to see the output is that being generated. Then you should view the nohup.out file! This command can be useful:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;tail -f nohup.out&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;So run the program in background and enjoy your time :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-2613425679255337842?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/2613425679255337842/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=2613425679255337842' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2613425679255337842'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2613425679255337842'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/03/run-python-script-as-background-process.html' title='run python script as a background process in linux'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-6911771837247542975</id><published>2008-03-06T22:46:00.000+06:00</published><updated>2008-03-06T22:52:39.604+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python freelance work'/><category scheme='http://www.blogger.com/atom/ns#' term='rentacoder'/><title type='text'>RentACoder.com - another place to look for freelance Python projects</title><content type='html'>Yes, in rentacoder.com you will find lots of projects including some python projects. If you are serious about freelance work, I think you should visit &lt;a href="http://pro-developer.blogspot.com/2008/02/rentacoder-work-from-your-home.html"&gt;here&lt;/a&gt; for a good start. I have seen lots of people get interested in freelance works, registers themselves and get frustrated as they can't win any bid. So read the blog post and get some ideas. As the writer in the &lt;a href="http://pro-developer.blogspot.com/2008/02/rentacoder-work-from-your-home.html"&gt;blog&lt;/a&gt; explained everything step-by-step.&lt;br /&gt;&lt;br /&gt;Happy bidding!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-6911771837247542975?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/6911771837247542975/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=6911771837247542975' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6911771837247542975'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6911771837247542975'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/03/rentacodercom-another-place-to-look-for.html' title='RentACoder.com - another place to look for freelance Python projects'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-4880564871471703907</id><published>2008-03-06T22:22:00.000+06:00</published><updated>2008-03-06T22:27:40.578+06:00</updated><title type='text'>What is your OS?</title><content type='html'>Another poll ended. This was the 2nd poll in this site. I asked my visitors about their operating system. In reply I got that 43% uses Windows, 37% Linux, 12% MAC.&lt;br /&gt;&lt;br /&gt;Now another poll is running. It's about your browser. Please vote.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-4880564871471703907?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/4880564871471703907/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=4880564871471703907' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/4880564871471703907'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/4880564871471703907'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/03/what-is-your-os.html' title='What is your OS?'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-5608727735888675344</id><published>2008-03-01T20:11:00.000+06:00</published><updated>2008-03-01T20:21:15.428+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='extract domain'/><category scheme='http://www.blogger.com/atom/ns#' term='python web crawler'/><category scheme='http://www.blogger.com/atom/ns#' term='python urlparse'/><title type='text'>extract domain name from url</title><content type='html'>Sometimes I need to find domain name from url in my program for various purposes (most of the time in my crawlers). So far I used the following function that takes an url and returns the domain name:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-size:120%;"&gt;&lt;br /&gt;def find_domain(url):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pos = url[7:].find('/')&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if pos == -1:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pos = url[7:].find('?')&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if pos == -1:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return url[7:]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;url = url[7:(7+pos)]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return url&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;But today I found a module named urlparse. So my function now looks like this:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-size:120%;"&gt;&lt;br /&gt;def find_domain2(url):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return urlparse(url)[1]&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;The new one is much better I think.&lt;br /&gt;&lt;br /&gt;Check &lt;a href="http://docs.python.org/lib/module-urlparse.html"&gt;urlparse&lt;/a&gt; for details.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-5608727735888675344?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/5608727735888675344/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=5608727735888675344' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/5608727735888675344'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/5608727735888675344'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/03/extract-domain-name-from-url.html' title='extract domain name from url'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-3672608254919510290</id><published>2008-02-27T23:48:00.000+06:00</published><updated>2008-02-27T23:59:52.624+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='swap values python'/><category scheme='http://www.blogger.com/atom/ns#' term='swap integers'/><title type='text'>swap values - the Python way</title><content type='html'>It's a very well known problem given to the beginners, 'swap values of two variables'. In our first introductory programming course (structured programming in C) we solved it in different ways. Most of us used another temporary variable. Some of us did some math tricks. I remember that one of my friend wrote the following code (in C):&lt;br /&gt;&lt;span style="font-size:120%;"&gt;&lt;code&gt;int a, b;&lt;br /&gt;scanf("%d %d", &amp;amp;a, &amp;amp;b);&lt;br /&gt;printf("%d %d\n", b, a);&lt;/code&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;And it made us laugh :-D&lt;br /&gt;&lt;br /&gt;Here is the pythonic way of doing this. Try the following code:&lt;br /&gt;&lt;span style="font-size:120%;"&gt;&lt;code&gt;a = 2&lt;br /&gt;b = 3&lt;br /&gt;print a, b&lt;br /&gt;a, b = b, a&lt;br /&gt;print a, b&lt;/code&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;:-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-3672608254919510290?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/3672608254919510290/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=3672608254919510290' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3672608254919510290'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/3672608254919510290'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/02/swap-values-python-way.html' title='swap values - the Python way'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-7562431481984190102</id><published>2008-02-27T10:20:00.000+06:00</published><updated>2009-01-26T02:07:18.366+06:00</updated><title type='text'>Links</title><content type='html'>&lt;a style="font-weight: bold;" href="http://speed-dev.blogspot.com/"&gt;High Speed Software Development&lt;/a&gt;&lt;br /&gt;A cool place to learn some tricks with Perl, PHP, Python, C# ... It also has lots of links to take the user at the right place.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://Link2Me.com" target="_blank"&gt;Link2Me Link Exchange Directory - The Best Link Exchange for SEO Professionals&lt;/a&gt;&lt;br&gt;Quality directory of webmasters actively seeking link exchange. Improve your search engine rankings and link popularity the easy way. Work clever not hard.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.xs4all.nl/~hwiegman" target="_blank"&gt;PeatSoft - Basic Programming and Software&lt;/a&gt;&lt;br&gt;GWBasic, QBasic, Visual Basic and ZX Spectrum programming, DESKTOP.INI info, games, tools and David Bowie midis&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.softxml.com" target="_blank"&gt;XML News Editor (SoftXML)&lt;/a&gt;&lt;br&gt;SoftXML as it sounds was born when XML was firstly introduced on web. We have been participating in XML development since its creation. It has been amazing to see how quickly the XML standard has been developed, and how quickly a large number of soft&lt;br /&gt;&lt;br /&gt;&lt;a href="http://dir.blogflux.com/cat/computers-tech.html"&gt;Directory of Computers/Tech Blogs&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://technology.totalblogdirectory.com"&gt;Technology Blog Directory&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.wilsdomain.com/" title="webdirectory"&gt;Web Directory&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.bsdmag.org" target="_blank"&gt;bsd magazine&lt;/a&gt;&lt;br&gt;BSD magazine is a quarterly totally devoted to different distros of BSD. The magazine comes with a DVD with the latest BSD distribution.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://brandnewsunglasses.com" target="_blank"&gt;Designer Sunglasses at Discount. Christian Dior Sunglasses, Bvlgari Sunglasses, Gucci Sunglasses and more.&lt;/a&gt;&lt;br&gt;Discount Sun Glasses. Designer Glasses Online. Chanel, Gucci, Prada... 2006 2007 New Authentic Shades &amp; Eyewear. Define your style with great buys on the hottest trends in mens &amp; womens fashion.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.bastillwork.net" target="_blank"&gt;Free software download, Get free license by post a review at BA-Software&lt;/a&gt;&lt;br&gt;BA-Software - Website provider the best software solution, Multimedia software, Security software, Graphics &amp; Design, Internet software, Developer tools, Utility tools, Ebook, software for Business and Personal.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.codeverge.net" target="_blank"&gt;ASP.net Computer Programming&lt;/a&gt;&lt;br&gt;ASP.net Computer Programming&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.resellrightsdownloads.com" target="_blank"&gt;ResellRightsDownloads- Turnkey Websites, Turn Key Business, Home Based Business.&lt;/a&gt;&lt;br&gt;resell rights, turnkey websites, turn key business for just £49.99, start your own home based business today, and we allow you free use of our downloads area for your own customers when you resell the package, make big money in no time at all.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.thedownloadswebstore.co.uk" target="_blank"&gt;thedownloadswebstore- Turnkey Websites, Software, Scripts, Graphics, Ebooks.&lt;/a&gt;&lt;br&gt;Turnkey Websites, Software, Scripts, Graphics, Ebooks And More, All At The Lowest Prices, And With Secure Paypal Payments, Instant Downloads And Full Resell Rights.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://programotion.scienceontheweb.net" target="_blank"&gt;Programotion. Aprende a programar paso a paso&lt;/a&gt;&lt;br&gt;Aqui dispondras de las nociones basicas para empezar, implementaciones de algoritmos y podras descubrir lenguajes de programacion como Pascal, Eiffel, C, o el ensamblador IA-32.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://freelance.dbperl.com" target="_blank"&gt;Freelance.dbPerl for freelance custom web design&lt;/a&gt;&lt;br&gt;Programmers, coders and consultants do work on bid contract basis for offshore projects in USA, Europe, India, Ukraine, Romania, Asia. Freelance custom web designers welcome&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.abs-sunglasses.com" target="_blank"&gt;Reading Glasses&lt;/a&gt;&lt;br&gt;Discount Designer Reading Glasses &amp;Sunglasses: auth. optical frames, safety lenses: Chanel Dior Dolce e Gabbana Gucci Bvlgari Prada Oakley.. Newest 2008, most popular 2007, popular old fashioned models. SMART EYEGLASSES SHOPPING-add lenses online&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.hot-world-softwares.ca" target="_blank"&gt;Hot World Softwares&lt;/a&gt;&lt;br&gt;There are some downloads,  games, SEO, everything you can find in there&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.fortuna-info.co.uk" target="_blank"&gt;A complete software solutions company&lt;/a&gt;&lt;br&gt;Fortuna InfoSolutions, is a software development and business consulting company. Expertise in CRM, Web based softwares, sites, desktop based systems.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://aris.bahagiasejahteradankeren.web.id" target="_blank"&gt;Point to Share&lt;/a&gt;&lt;br&gt;trying to write about sharepoint, .Net framerwork, OOP, and UML&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.lush-sensations.co.uk" target="_blank"&gt;Kinky Lingerie&lt;/a&gt;&lt;br&gt;Lingerie, basques and underwear&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.planetvisiononline.co.uk" target="_blank"&gt;christmas gifts&lt;/a&gt;&lt;br&gt;planetvision offers a wide variety of gadgets and gifts for christmas and birthdays all ages catered for&lt;br /&gt;&lt;br /&gt;&lt;a href="http://manpradasunglasses.com" target="_blank"&gt;Authentic Prada SunGlasses.&lt;/a&gt;&lt;br&gt;Draw attention to really inexpensive authentic discount designer sunglasses and eyewear online such as Oakley, Chanel, Chopard, Christian Dior, Dolce Gabbana, Gattinoni, Gianni Versace, Giorgio Armani, Gucci, Prada, Revo...&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.mysexhealth.co.uk" target="_blank"&gt;VigRX Plus&lt;/a&gt;&lt;br&gt;UKs Cheapest VigRX Plus, free discreet delivery available on all orders.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://xpirtdesign.com" target="_blank"&gt;Orange County Web Design&lt;/a&gt;&lt;br&gt;Orange County Web Design, Search Engine Optimization (SEO), Affordable Custom Web Design Company servicing businesses and individuals nationwide.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.vig-rx.es" target="_blank"&gt;Alargamiento Del Pene&lt;/a&gt;&lt;br&gt;vigrx -  no1 en Alargamiento de Pene en USA e Inglaterra&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.specialfreelancer.com" target="_blank"&gt;Special Freelancers for Projects&lt;/a&gt;&lt;br&gt;Online market place for freelancers and projects owners&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.transmiami.com" target="_blank"&gt;Miami Limousine Florida - airport port transportation&lt;/a&gt;&lt;br&gt;Luxury sedan and limo service for Miami, Ft Lauderdale, Palm Beach and all Florida Keys&lt;br /&gt;Miami airport and Port of Miami transportation. Covering South Beach and Key West.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.mobilebroadbandonline.co.uk" target="_blank"&gt;Mobile Broadband&lt;/a&gt;&lt;br&gt;Compare mobile broadband available in the uk. Compare these packages to standard broadband packages and see the advantages and disadvantages of mobile broadband.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.adddirectoryeasy.com" target="_blank"&gt;Add Your Website To The Best Web Directory Network.&lt;/a&gt;&lt;br&gt;Add your website to our network, your website will be accessed by more than 10,000 user everyday.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.boka-restresor.se" target="_blank"&gt;restresor&lt;/a&gt;&lt;br&gt;Sista minuten resor, eller restresor, blir ofta betydligt billigare an vanliga charterresor. Med restresor reser du billigt.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.specialfreelancer.com" target="_blank"&gt;Special Freelancers for Projects&lt;/a&gt;&lt;br&gt;Online market place for freelancers and projects owners&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.home-contractor-house-renovations.com" target="_blank"&gt;Home Contractor, House Renovations.&lt;/a&gt;&lt;br&gt;Revovations/contract work for houses/homes in Toronto. Installation and maintenance services include kitchens, basements, bathrooms, finishings, decks, fences, excavation, masonry, flagstone, framing and more. Call today for a free estimate.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.comparebroadbandpackages.co.uk" target="_blank"&gt;Compare Broadband Packages&lt;/a&gt;&lt;br&gt;Compare broadband packages provides detailed analysis of the broadband packages currently available in the UK&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.gojewelryshop.com" target="_blank"&gt;Discount Mens Jewelry, Mens Rings, Gifts For Him, Mens Bracelets&lt;/a&gt;&lt;br&gt;Shop for great jewelry and gifts for men, including stainless rings, earrings, bracelets, and pendants, at incredibly low prices with free shipment.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.127hosting.com" target="_blank"&gt;Website Design - Web Design Tutorials&lt;/a&gt;&lt;br&gt;Web design hosting &amp; tutorial website. Thousands of free tutorial videos.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://knickers.lush-sensations.co.uk" target="_blank"&gt;Sexy Underwear&lt;/a&gt;&lt;br&gt;Basques, Underwear and Fancy Dress Costumes. Sexy Clothing, Crotchless Knickers, Naughty Nightwear, Lingerie Kinky Lingerie and Sexy Underwear. Free Delivery.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.physio123.com" target="_blank"&gt;physiotherapy websites&lt;/a&gt;&lt;br&gt;Physio123 provide physiotherapy website design and seo for physiotherapy clinics and physiotherapy  providers.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.rent-acoder.com" target="_blank"&gt;Rent A Coder - Hire freelancers - Outsource projects - Webdesign - Work From home - Programming&lt;/a&gt;&lt;br&gt;Rent A Coder, Outsourcing jobs, A place to list your projects, Freelancers market, How to Hire a coder, How to Rent for programming, Freelance programmer, Work from Home, Cheap quality coders, Low project &amp; bid comision, Find a coder for your project&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.quintas.com.pt" target="_blank"&gt;O sitio do Quintas&lt;/a&gt;&lt;br&gt;Videos de travestis e transformistas,nacionais e internacionais. O melhor de cada familia no sitio do quintas.Video,music and fun for all.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.slash.in" target="_blank"&gt;Get 50% Discount on Web Hosting with FREE Domain, Website Design, Website Templates, Search Engine Submission, SEO.&lt;/a&gt;&lt;br&gt;Slash.IN Bangalore based Company specialized in Website Designing, Website Hosting, Windows Hosting, Linux Hosting, SEO, Search Engine Submissions, Selling Premium Website Templates, Templates Customizing, Get 40% Discount on all Hosting Plans &amp; more&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.specialfreelancer.com" target="_blank"&gt;Special Freelancers for Projects&lt;/a&gt;&lt;br&gt;Online market place for freelancers and projects owners&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.hitta-festlokal.se" target="_blank"&gt;Festlokal&lt;/a&gt;&lt;br&gt;Hitta din festlokal hos oss. En rolig fest ar beroende av ratt festlokal, stor eller liten. Se till att skaffa en bra festlokal idag.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.craftvillage.net" target="_blank"&gt; Craft Village&lt;/a&gt;&lt;br&gt;Craft Village contains five areas of exploration. They are cooking, sewing, quilting, home decor, and knitting. We offer free recipes and projects for all abilities. There is also a resource page and more. The projects change weekly. Archived.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.russian-rendezvous.co.uk" target="_blank"&gt;Russian Wife&lt;/a&gt;&lt;br&gt;Hi Welcome to Russian Rendezvous’s updated website. Run by myself Nick &amp; my Russian wife Lilya. We have been putting men and ladies together now for over 10 years&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.eazycomp.com" target="_blank"&gt;eaZycomp-Computer Services London&lt;/a&gt;&lt;br&gt;Professional PC and Laptop Repairs, Installation, Support, Maintenance, 24 Hour Service for Homes and Businesses, Wireless networking and more&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.chimecottagemusic.com" target="_blank"&gt;Chime Cottage Music - specialist online CD shop.&lt;/a&gt;&lt;br&gt;Online CD/MP3 shop for progressive rock, synth rock, electronica, ambient and New Age sounds.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.createwebsite.biz" target="_blank"&gt;Createwebsite.biz - Build a Website, Create a Website, web hosting, web design, templates, CMS, Ad Free Hosting, Free Domain Name, Make Your Website with our Builder&lt;/a&gt;&lt;br&gt;Make your own website with our website builder - website templates, content management system (CMS), ad-free hosting, ecommerce and real estate solutions, website design and web page design services to create a website at Createwebsite.biz&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-7562431481984190102?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/7562431481984190102'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/7562431481984190102'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/02/links.html' title='Links'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-2436331958566779663</id><published>2008-02-27T09:13:00.000+06:00</published><updated>2008-02-27T09:23:46.512+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python web spider'/><category scheme='http://www.blogger.com/atom/ns#' term='python web crawler'/><category scheme='http://www.blogger.com/atom/ns#' term='python download file'/><title type='text'>How to download a file using Python?</title><content type='html'>Couple of weeks ago, I had to write a spider that harvest data from a website into a csv file and download the images. First I was thinking how to do the download... then I came up with a simple idea and wrote a function save_image that takes the url of the jpg image and filename, downloads the file and saves it with the name given in filename.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-size:120%;"&gt;import urllib2&lt;br /&gt;&lt;br /&gt;def save_image(url, filename):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;usock = urllib2.urlopen(url)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;data = usock.read()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;usock.close()  &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fp = open(filename, 'wb')&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fp.write(data)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fp.close()&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Actually I just write the file in binary mode. Now post your code that performs this task is a different manner.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-2436331958566779663?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/2436331958566779663/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=2436331958566779663' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2436331958566779663'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2436331958566779663'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/02/how-to-download-file-using-python.html' title='How to download a file using Python?'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-5777411146751773957</id><published>2008-02-26T00:37:00.000+06:00</published><updated>2008-02-26T00:46:02.887+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='getacoder'/><category scheme='http://www.blogger.com/atom/ns#' term='python freelance work'/><title type='text'>GetACoder for freelance Python projects</title><content type='html'>GetACoder.com is a good place for freelancers where you can search for Python projects (of course you can search for other projects also, not only Python :)&lt;br /&gt;&lt;br /&gt;Go &lt;a href="http://www.getacoder.com/projects/python_127.htm"&gt;here&lt;/a&gt; for Python projects.&lt;br /&gt;&lt;br /&gt;There are lot of websites / blogs that can help you to be a successful freelancer. So I don't want to write these things here. Just one line, 'have patience and be honest'.&lt;br /&gt;&lt;br /&gt;Have fun with Python!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-5777411146751773957?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/5777411146751773957/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=5777411146751773957' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/5777411146751773957'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/5777411146751773957'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/02/getacoder-for-freelance-python-projects.html' title='GetACoder for freelance Python projects'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-7882556972337905420</id><published>2008-02-23T11:57:00.000+06:00</published><updated>2008-02-23T12:07:55.081+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='user agent'/><category scheme='http://www.blogger.com/atom/ns#' term='urllib2'/><category scheme='http://www.blogger.com/atom/ns#' term='user-agent'/><category scheme='http://www.blogger.com/atom/ns#' term='web spider'/><category scheme='http://www.blogger.com/atom/ns#' term='web crawler'/><title type='text'>Use user agent in your spider</title><content type='html'>Some websites don't allow your spider to scrape the pages unless you use an user-agent in your code. You can fool the websites using user-agent so that they understand that the request is coming from a browser. Here is a piece of code that use user agent 'Mozilla 5.0' to get the html content of a website:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-size:120%;"&gt;import urllib2&lt;br /&gt;&lt;br /&gt;url = "http://www.example.com" #write your url here&lt;br /&gt;opener = urllib2.build_opener()&lt;br /&gt;opener.addheaders = [('User-agent', 'Mozilla/5.0')]&lt;br /&gt;usock = opener.open(url)&lt;br /&gt;url = usock.geturl()&lt;br /&gt;data = usock.read()&lt;br /&gt;usock.close()               &lt;br /&gt;print data&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;You can use other user agent as well. For example, the user agent my Firefox browser uses:&lt;br /&gt;"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.12) Gecko/20061201 Firefox/2.0.0.12 (Ubuntu-feisty)"&lt;br /&gt;&lt;br /&gt;What is your user agent?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-7882556972337905420?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/7882556972337905420/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=7882556972337905420' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/7882556972337905420'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/7882556972337905420'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/02/use-user-agent-in-your-spider.html' title='Use user agent in your spider'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-9027326634666250124</id><published>2008-02-23T03:24:00.000+06:00</published><updated>2008-02-23T03:28:55.129+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python 2.5.2'/><title type='text'>Python 2.5.2 released!</title><content type='html'>Final version of Python 2.5.2 is released!&lt;br /&gt;&lt;br /&gt;Download it from here: &lt;a href="http://www.python.org/download/releases/2.5.2/"&gt;http://www.python.org/download/releases/2.5.2/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;From python.org:&lt;br /&gt;&lt;blockquote&gt;This is the second bugfix release of Python 2.5. Python 2.5 is now in bugfix-only mode; no new features are being added. According to the release notes, over 100 bugs and patches have been addressed since Python 2.5.1, many of them improving the stability of the interpreter, and improving its portability.&lt;/blockquote&gt;&lt;br /&gt;Read the release notes for more: &lt;a href="http://www.python.org/download/releases/2.5.2/NEWS.txt"&gt;http://www.python.org/download/releases/2.5.2/NEWS.txt&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-9027326634666250124?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/9027326634666250124/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=9027326634666250124' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/9027326634666250124'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/9027326634666250124'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/02/python-252-released.html' title='Python 2.5.2 released!'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-9048107802207724318</id><published>2008-02-21T23:35:00.000+06:00</published><updated>2008-02-21T23:44:21.247+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='execute'/><category scheme='http://www.blogger.com/atom/ns#' term='linux command'/><category scheme='http://www.blogger.com/atom/ns#' term='python'/><title type='text'>Execute Linux commands in Python</title><content type='html'>For last few days, I am doing an interesting project, for which I require to execute some Linux commands from Python. So I searched a bit for it and found an way to do it. For example if I want to run the command 'ls -lt', I can use the following code:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-size:120%;"&gt;import os&lt;br /&gt;os.system('ls -lt')&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;But problem is I want to store the result in a list. Then I thought of writing the output to a file and read the file into a list. My code was:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-size:120%;"&gt;import os&lt;br /&gt;os.system('ls -lt &gt; output.txt')&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Can you suggest a better way?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-9048107802207724318?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/9048107802207724318/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=9048107802207724318' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/9048107802207724318'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/9048107802207724318'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/02/execute-linux-commands-in-python.html' title='Execute Linux commands in Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-203937592989219314</id><published>2008-02-20T23:58:00.001+06:00</published><updated>2008-02-21T00:00:08.547+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python version'/><title type='text'>which Python version do you use?</title><content type='html'>Yes, this was the first poll in this blog. 9 people voted for Python 2.5 and 1 voted for 3.0&lt;br /&gt;&lt;br /&gt;I myself still use Python 2.5.1, waiting for the final release of 3.0... :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-203937592989219314?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/203937592989219314/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=203937592989219314' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/203937592989219314'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/203937592989219314'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/02/which-python-version-do-you-use.html' title='which Python version do you use?'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-7854327606847941545</id><published>2008-02-19T23:07:00.000+06:00</published><updated>2008-03-01T20:27:38.383+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python'/><category scheme='http://www.blogger.com/atom/ns#' term='round'/><category scheme='http://www.blogger.com/atom/ns#' term='floating point number'/><title type='text'>How to round a floating point number?</title><content type='html'>It's another problem I faced few days ago. I needed to round a floating point number to two digits after decimal place. Then I found a function named 'round()'. Look at the following code block written in Python:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-size:120%;"&gt;d = 10.0 / 3&lt;br /&gt;print d&lt;br /&gt;d = round(d, 2)&lt;br /&gt;print d&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-7854327606847941545?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/7854327606847941545/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=7854327606847941545' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/7854327606847941545'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/7854327606847941545'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/02/how-to-round-floating-point-number.html' title='How to round a floating point number?'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-2835367199414854922</id><published>2008-02-19T00:32:00.000+06:00</published><updated>2008-02-21T23:48:05.893+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='web spider'/><category scheme='http://www.blogger.com/atom/ns#' term='web crawler'/><category scheme='http://www.blogger.com/atom/ns#' term='url redirect'/><title type='text'>Get Original URL</title><content type='html'>Once I got into trouble while crawling some websites. Some of the URL I had wasn't the original URL, rather they were redirecting to some other URL. Then I came up with a function to get the original URL. Here I share it with you:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-size:120%;"&gt;def get_original_url(url):&lt;br /&gt;"""This function takes an url and returns the original url with cookie (if any)&lt;br /&gt;"""&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cj = cookielib.CookieJar()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;opener.addheaders = [('User-agent', 'Mozilla/5.0')]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;usock = opener.open(url)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;url = usock.geturl()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;usock.close()  &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return url, cj&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Please send me your comments on this piece of code.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-2835367199414854922?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/2835367199414854922/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=2835367199414854922' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2835367199414854922'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2835367199414854922'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/02/get-original-url.html' title='Get Original URL'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-6645499257123178407</id><published>2008-02-16T23:58:00.000+06:00</published><updated>2008-02-17T00:05:27.342+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python freelance work'/><title type='text'>Python projects in GetAFreelancer</title><content type='html'>If you are interested in some freelance works using Python, there are several websites where you can search for projects. GetAFreelancer.com is one of them. You can find python projects here: &lt;a href="http://getafreelancer.com/projects/by-job/Python.html"&gt;http://getafreelancer.com/projects/by-job/Python.html&lt;/a&gt;&lt;br /&gt;If you don't have time to work on projects, still, browsing the projects will help you to get some ideas about the real world application of Python.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-6645499257123178407?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/6645499257123178407/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=6645499257123178407' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6645499257123178407'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/6645499257123178407'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/02/python-projects-in-getafreelancer.html' title='Python projects in GetAFreelancer'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-2879599763720289681</id><published>2008-02-16T02:40:00.000+06:00</published><updated>2008-02-16T02:52:51.874+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python command line argument'/><title type='text'>Command Line Arguments in Python</title><content type='html'>Another problem the beginner in Python faces 'to take input from the command line arguments' - maybe you want to give a text file name as a command line argument or you need it for another purpose (in the first time, my necessity was the earlier one).&lt;br /&gt;&lt;br /&gt;The solution is to use &lt;span style="font-weight: bold;"&gt;sys.argv&lt;/span&gt; you need to import the &lt;span style="font-weight: bold;"&gt;sys&lt;/span&gt; module first. then &lt;span style="font-weight: bold;"&gt;sys.argv[0]&lt;/span&gt; contains the python filename itself, &lt;span style="font-weight: bold;"&gt;sys.argv[1]&lt;/span&gt; contains the next argument and so on...&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;import sys&lt;br /&gt;&lt;br /&gt;print 'I am ', sys.argv[0]&lt;br /&gt;print sys.argv[1]&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;Run the program: &lt;span style="font-weight: bold;"&gt;python my.py file.txt&lt;/span&gt;&lt;br /&gt;Now you may assign the &lt;span style="font-weight: bold;"&gt;sys.argv[1]&lt;/span&gt; to a variable and do whatever you want.&lt;br /&gt;&lt;br /&gt;To know more about sys module, Check &lt;a href="http://docs.python.org/lib/module-sys.html"&gt;http://docs.python.org/lib/module-sys.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Hope you find this tip useful :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-2879599763720289681?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/2879599763720289681/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=2879599763720289681' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2879599763720289681'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/2879599763720289681'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/02/command-line-arguments-in-python.html' title='Command Line Arguments in Python'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1902979661984927761.post-8501784321567193874</id><published>2008-02-13T02:33:00.000+06:00</published><updated>2008-02-13T02:43:02.190+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='code search'/><title type='text'>Search Python code in Krugle</title><content type='html'>I found an interesting search engine that searches for source code. Visit &lt;a href="http://www.krugle.org/kse/files"&gt;http://www.krugle.org/kse/files&lt;/a&gt; and try your search for your desired programming language. &lt;br /&gt;&lt;br /&gt;Interesting thing about krugle is not only that you can search code of your desired language, you can specify where it should search the keyword - in source code or comment or documentation ...&lt;br /&gt;&lt;br /&gt;Hope you will find the site useful :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1902979661984927761-8501784321567193874?l=love-python.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://love-python.blogspot.com/feeds/8501784321567193874/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1902979661984927761&amp;postID=8501784321567193874' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/8501784321567193874'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1902979661984927761/posts/default/8501784321567193874'/><link rel='alternate' type='text/html' href='http://love-python.blogspot.com/2008/02/search-python-code-in-krugle.html' title='Search Python code in Krugle'/><author><name>Tamim Shahriar (Subeen)</name><uri>http://www.blogger.com/profile/03476580865735017742</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='26' src='http://2.bp.blogspot.com/-FIT_lTIEXCA/TkjB0O6_XEI/AAAAAAAAAqs/6PQZ2D1Gkl4/s220/sbn_pic_book.jpg'/></author><thr:total>0</thr:total></entry></feed>
