eECHO BLOG

A journey of a thousand miles starts with a single step.

Archive for the ‘Python’ Category

Introducing List Filtering

>>> li = ["a", "mpilgrim", "foo", "b", "c", "b", "d", "d"] >>> [elem for elem in li if len(elem) > 1]       1 ['mpilgrim', 'foo'] >>> [elem for elem in li if elem != "b"]         2 ['a', 'mpilgrim', 'foo', 'c', 'd', 'd'] >>> [elem for elem in li if li.count(elem) == 1] 3 ['a', 'mpilgrim', 'foo', 'c'] [...]

More powerful command line option parser

http://docs.python.org/library/optparse.html New in version 2.3. optparse is a more convenient, flexible, and powerful library for parsing command-line options than the old getopt module. optparse uses a more declarative style of command-line parsing: you create an instance of OptionParser, populate it with options, and parse the command line. optparse allows users to specify options in the [...]

pip is meant to improve on easy_install. Some of the improvements:

pip is a replacement for easy_install. It uses mostly the same techniques for finding packages, so packages that were made easy_installable should be pip-installable as well. pip is meant to improve on easy_install. Some of the improvements: * All packages are downloaded before installation. Partially-completed installation doesn’t occur as a result. * Care is taken [...]

virtualenv is a tool to create isolated Python environments.

The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python2.4/site-packages (or whatever your platform’s standard location is), it’s easy to end [...]

Fabric is a simple pythonic remote deployment tool.

It is designed to upload files to, and run shell commands on, a number of servers in parallel or serially. These commands are grouped in tasks (regular python functions) and specified in a ‘fabfile.’ This is called remote automation, and the primary use case is deploying applications to multiple similar hosts. Although it is easier [...]

In Python, there is a distinction between bound and unbound methods.

In Python, there is a distinction between bound and unbound methods. Basically, a call to a member function (like method_one), a bound function a_test.method_one() is translated to Test.method_one(a_test) i.e. a call to an unbound method. Because of that, a call to your version of method_two will fail with a TypeError >>> a_test = Test() >>> [...]

python ssh

I have research on how to access ssh using python: 1. Twisted – an event-driven networking engine written in Python. 2. Paramiko – implements the SSH2 protocol for secure connections to remote machines. 3. Pexpect – spawn a child application and control it as if a human were typing commands. Three libraries have used different [...]

Pexpect

Pexpect is a Python module for spawning child applications and controlling them automatically. Pexpect can be used for automating interactive applications such as ssh, ftp, passwd, telnet, etc. It can be used to a automate setup scripts for duplicating software package installations on different servers. It can be used for automated software testing. Pexpect is [...]

Installing the Python Paster Utility on Ubuntu

http://www.speedbreeze.com/2008/01/19/installing-the-python-paster-utility-on-ubuntu/ January 19, 2008 @ 10:53 pm A few weeks ago, I wanted to develop a few new themes for Plone 3. When I looked around for an article on how to create the base files for a new theme, I found davcovent’s article about how to develop Plone 3 themes. After reading the article, [...]

Understanding Unicode

Some Background on Characters Before we see what Unicode is, it makes sense to step back slightly to think about just what it means to store “characters” in digital files. Anyone who uses a tool like a text editor usually just thinks of what they are doing as entering some characters—numbers, letters, punctuation, and so [...]