Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Oct 032010

How to install Easy Install for Python in Ubuntu


EasyInstall is a package manager for the Python programming language that provides a standard format for distributing Python programs and libraries (based on the Python Eggs wrapper).

To install the EasyInstall under Ubuntu, type:

# sudo apt-get install python-setuptools python-dev build-essential

May 292010

What is "The Zen of Python"?


Try the following command in shell:

# python -c "import this"

And it will print out...

The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
May 222010

How to debug in Python?


Assume you have a simple python script like:

a = 1
b = 2
c = a + b
print c

To enable debugging, add the following line at the top of the program

import pdb

and in the line you want to break, add


So the whole program become:

import pdb
a = 1
b = 2
c = a + b
print c

When you execute the script by python, you will in the debug mode.

Some useful commands:

1. Print variables: p a
2. Step over: n
3. Continue: c
4. Quit: q