Most Frequently Used Python Code Fragments

Python syntax may seem strange at the beginning for Java developers. Wouldn’t it be nice if we first see how Python does the common jobs that we have done using other programming languages, like Java? The common code fragments are call “code idioms”. Reading the code idioms of a programming language is often helpful, and can be served as a shortcut for learning a new programming language.

Read more

Python read data from MySQL database

The following code can read data from MySQL database. import MySQLdb   # Open database connection db = MySQLdb.connect("localhost","username","password","DBName")   # prepare a cursor object using cursor method cursor = db.cursor()   sql = "select * from table1" cursor.execute(sql) results = cursor.fetchall() for row in results: print row[0]   # disconnect from server db.close()import MySQLdb … Read more

Java vs. Python (1): Simple Code Examples

Some developers have claimed that Python is more productive than Java. It is dangerous to make such a claim, because it may take several days to prove that thoroughly. From a high level view, Java is statically typed, which means all variable names have to be explicitly declared. In contrast, Python is dynamically typed, which … Read more

Error message during installation of PyDev for Eclipse

Eclipse version: Indigo Platform: Ubuntu 11.10 Error message: An error occurred while collecting items to be installed session context was:(profile=epp.package.java, phase=org.eclipse.equinox.internal.p2.engine.phases.Collect, operand=, action=). No repository found containing: osgi.bundle,javax.mail.glassfish,1.4.1.v201005082020 This is possibly caused by in compatible eclipse version. If we use Help -> Eclipse MarketPlace to install PyDev, the problem is gone.

Python “Hello World” web application in Ubuntu

This post shows how to setup a python web development environment under Ubuntu and make a hello world example. So Python has become a hot word in recent years. But before you can do anything about it, you need a “hello world” sample application. In this post, I will build a hello world Python web … Read more