Have you ever needed the colouring of text in your console-based program?

Doing this in Python is really simple but annoying, so if you want a pre-made function, you’ve to just download the script I’ll speak about.

You can download it from here.

The syntax for using it is the same used for printing a function’s return value.

import color_markup_string as cms
print cms.color("<green>Apple green.</green>")
print cms.color("<red>Apple red.</red>")
print cms.color("<yellow>Apple yellow.<yellow>")

Comments 2 Comments »

The sorting problem is one of the most common in the computer science. In this post I’ll speak about one of the simplest algorithm, but also one of the most unefficient.

From Wikipedia:

Comments 1 Comment »

Today I’ve decided to see how PYHP (a good imitation of PHP, but in Python) works.

Even though I think that embedding source code (Python in this case) in the html file is not a good way to write a good web application, I’ve given a look to this new library (it’s at its second alpha).

Comments No Comments »

In the previous post I’ve spoken about Boost.Python. (To read this article in Italian, go here).

In this post I’ll try to explain you how to use Boost to create a Python module to find perfect numbers.

If you’ve not installed Boost.Python I suggest you to read the appropriate guide. (If you use Debian based systems, you can also read this guide)

Comments 2 Comments »

Today I’ve written a little howto to install Boost.Python, a library that allows you to create Python modules in C++, on Debian (and Debian based systems, such as Ubuntu)

Why have I written this howto?

If you surf on the Internet you may notice that the most part of the Debian users/developers who have installed this library (and not only for Debian!) have experienced troubles with the tutorial/quickstart.

Comments 1 Comment »

In mathematics and the arts, two quantities are in the golden ratio if the ratio between the sum of those quantities and the larger one is the same as the ratio between the larger one and the smaller. The golden ratio is approximately 1.6180339887. ( Wikipedia )

Since the ancient Greeks this number has a really particular value: it represents a sort of “perfection”, if you want.

Comments No Comments »

Recently, I’ve had a discussion in the python-it.org’s forum about the Python ternary operator.

I’ve asked why doesn’t exist the C ternary operator:

   <condition> ? <expression 1> : <expression 2>

The conclusion is that Guido Van Rossum rejected it years ago.

But he decided to add a new ternary operator in Python 2.5.

I know, Python 2.5 has been released two years ago, but I was curious!

Comments 1 Comment »

You may have noticed that there aren’t more Python lessons’ pages.

I’ve decided to review them, because I’ve a little doubt about these lessons.

I want to rewrite them from zero.

If you’ve any suggestion, please contact me.

Comments No Comments »

In this post I’ll explain you a little tip useful when you’re using conditional statements in Python.

There are some ways to use “if/elif/else” in Python, and you know well what these are.
Imagine you want to check all the students’ grades (greater than 60) and you know that the most part of them is good at school, you’ve two ways to do this:

  • Using nested if/else statements

Comments 2 Comments »

In the Python-it community, Gennaro Porpora has developed for us a really useful script: Py2deb.
In practice it builds a debian package simply adding some command line parameters when you run it.

In this post I’ll explain you how to use it.

Above all, you need a “Bash” shell. Now download the script from here.

Then you need to change the attribute to this script:

Comments 4 Comments »