>>> 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']
1 The mapping expression here is simple […]
Archive for the ‘Python’ Category
Introducing List Filtering
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 conventional GNU/POSIX […]
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.
[…]
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 to automate […]
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()
>>> a_test.method_two()
Traceback (most recent call last):
File […]
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 […]
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 in the spirit of […]
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, I tried […]
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 on. […]
List of object-relational mapping software
http://en.wikipedia.org/wiki/List_of_object-relational_mapping_software
List of object-relational mapping software
From Wikipedia, the free encyclopedia
Jump to: navigation, search
This is a list of well-known object-relational mapping software. This list is neither up-to-date nor all-inclusive.
Contents
[hide]
* 1 C++
* 2 Delphi
* 3 Groovy
* 4 Java
* […]
Parsing XML with pulldom and internal entities
http://www.python.org/doc/2.6/library/xml.dom.html#documenttype-objects
http://xmlfiles.com/dtd/dtd_building.asp
http://xmlfiles.com/dtd/
Please support our Python advertiser: Programming Forums
These search terms have been highlighted: ENTITY or ENTITIES xml python (Clear)
Reply
•
•
Posts: 3
Reputation: wdyck is an unknown quantity at this point
Solved Threads: 1
wdyck wdyck is offline Offline
Newbie Poster
Parsing XML with pulldom and internal entities
#1
Jun 24th, 2008
I am parsing an XML file with encoded entities in it (& […]
unescape Removes HTML or XML character references
def unescape(text):
"""Removes HTML or XML character references
and entities from a text string.
@param text The HTML (or XML) source text.
@return The plain text, as a Unicode string, if necessary.
from Fredrik Lundh
2008-01-03: input only unicode characters string.
http://effbot.org/zone/re-sub.htm#unescape-html
"""
def fixup(m):
text = m.group(0)
if text[:2] == "&#":
# character reference
try:
if text[:3] == "&#x":
return unichr(int(text[3:-1], 16))
else:
return unichr(int(text[2:-1]))
except ValueError:
print "Value Error"
pass
else:
# named entity
# reescape […]
Available settings
This document is for Django’s SVN release, which can be significantly different from previous releases. Get old docs here: Django 1.0
Available settings¶
Here’s a full list of all available settings, in alphabetical order, and their default values.
ABSOLUTE_URL_OVERRIDES¶
Default: {} (Empty dictionary)
A dictionary mapping “app_label.model_name” strings to functions that take a model object and return its URL. […]
Active record pattern
In software engineering, the active record pattern is a design pattern frequently found in software that stores its data in relational databases. It was named by Martin Fowler in his book Patterns of Enterprise Application Architecture.
Active record is an approach to access data in a database. A database table or view is wrapped into a […]
filename from path python
>>> import os
>>> os.path.basename('c:/windows/desktop/python.py')
'python.py'
>>>
The BuildBot
The BuildBot is a system to automate the compile/test cycle required by most software projects to validate code changes. By automatically rebuilding and testing the tree each time something has changed, build problems are pinpointed quickly, before other developers are inconvenienced by the failure. The guilty developer can be identified and harassed without human intervention. […]
Pylons is a lightweight web framework
emphasizing flexibility and rapid development.
Download Latest Version: 0.9.7
Why use Pylons?
Pylons combines the very best ideas from the worlds of Ruby, Python and Perl, providing a structured but extremely flexible Python web framework. It’s also one of the first projects to leverage the emerging WSGI standard, which allows extensive re-use and flexibility — but only if […]
Key Features of SQLAlchemy
http://www.sqlalchemy.org/features.html
Some of the key features at a glance:
Supported Databases
SQLAlchemy includes dialects for SQLite, Postgres, MySQL, Oracle, MS-SQL, Firebird, MaxDB, MS Access, Sybase and Informix; IBM has also released a DB2 driver. The corresponding DB-API 2.0 implementation (or sometimes one of several available) is required to use each particular database.
Unit Of Work
The Unit Of […]
Observer python
This is used to notify a list of objects with a state change.
Observer allows adding features in an application in a pluggable way by de-coupling
the new functionality from the existing code base. An event framework is a typical
implementation of the Observer pattern and is described in the figure that follows.
Every time an event occurs, all […]
