Posts

Showing posts from September, 2008

Remove duplicate items from a list using set

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. myList = list(set(myList)) Here is a python example: >>> myList = [1, 2, 3, 3, 2, 2, 4, 5, 5] >>> myList [1, 2, 3, 3, 2, 2, 4, 5, 5] >>> myList = list(set(myList)) >>> myList [1, 2, 3, 4, 5] >>> Let me know if you use any different technique to remove duplicates from a list.

use proxy and cookie together in Python

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. import urllib2 import cookielib # create cookiejar to store cookie cj = cookielib.CookieJar() # IP:PORT proxy_address = '66.98.208.8:3128' # change the IP:PORT, this one is for example # create the proxy handler proxy_handler = urllib2.ProxyHandler({'http': proxy_address}) # create opener opener = urllib2.build_opener(proxy_handler, urllib2.HTTPCookieProcessor(cj)) # install the opener urllib2.install_opener(opener) # url to browse / visit url = "http://www....com/" # change the url req=urllib2.Request(url) data=urllib2.urlopen(req).read() print data # now write the data to a text file # create file handler fh = open('page.txt', 'w') data = "".join(data) # write to file fh.write(data) # close the file handler fh.close() Hope you will find th

Py2SIS create sis file to make standalone application

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. Format of the command is: py2sis [sisfile] [--uid=0x12345678] [--appname=myapp] [--presdk20] [--leavetemp] I used the following command to create SIS file for my program: F:\Nokia\Tools\Python_for_Series_60\py2sis>py2sis.exe dse_stock_tracker.py dse.sis --uid 0x12345678 --appname=DSEStockPriceTracker 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.

The A-Z of programming languages: Python

Computer world published an interesting article - The A-Z of programming languages: Python . Actually it's an interview of Guido van Rossum - 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.