ParTecs Weblog

ParTecs Plone Widgets go sourceforge

January 13th, 2007

I am happy to announce that our major GPL Plone Widgets will be now maintained and released on SourceForge.net.

We thank everybody helping on these projects. Our other widgets are still available from our website and if interest grows we’ll be happy to maintain another sf.net project page.

We invite all developers willing to help making PloneSkype, PloneInvite and PloneCaptcha really useful products for the community to join efforts. So, if you have the will, don’t hesitate in joining the mailing lists linked above and start getting your hands dirty with python.

TestableEmailer – Version 0.9.1 Released

June 29th, 2006

This is a bug fix version that addresses some problems related to persistence. This tool itself has been well tested from the automated acceptance test suite of our soon to be released PloneConsensus.

Get the latest version here

Two algorithms to sort a dictionary by it’s value

February 27th, 2006

Here are 2 algorithms that I’ve use to sort dictionaries by their values. I have yet to profile both algorithms to see what works best in a senario. Personnally I feel the first method is more cognitive to Python developers.
Method 1 – Here I have converted the dictionary to a list of tuple (key, value) pairs. Further I have sorted the list by comparing the tuples second element.

>>> a = {1: 4, 2: 5, 4: 6, 7: 4} >>> sorted_dict = list(a.iteritems()) >>> sorted_dict.sort(lambda i1, i2: cmp(i1[1], i2[1])) >>> for key, value in sorted_dict: ... print key, value ... 1 4 7 4 2 5 4 6

Method 2 – In this case I have constructed a dictionary whose keys are the values of the dictionary I wanted sorted. The values of newly constructed dictionary is composed of a list of all the keys with the same value.

>>> for key, value in a.iteritems(): ... if sorted_dict.has_key(value): ... sorted_dict[value].append(key) ... continue ... sorted_dict[value] = [key] ... >>> for value, keys in sorted_dict.iteritems(): ... for key in keys: ... print key, value ... 1 4 7 4 2 5 4 6

Source inspector

February 27th, 2006

The .pythonrc.py is the script that executes when interactive interpreter starts up. You need to unsure that an environment variable PYTHONSTARTUP contains the path to that file.

export PYTHONSTARTUP=/home/partecs/.pythonrc.py

Here is a handy code snippet that one could add into your .pythonrc.py file.

import pydoc
import inspect
import rlcompleter, readline

readline.parse_and_bind('tab: complete')

def source(obj):
"""source of the obj."""
try:
pydoc.pipepager(inspect.getsource(obj), 'less')
except IOError:
pass

Now for the fun part, run the Python interpreter and hit the tab button twice. You have the tab complete feature. Also try out the following statements.

>>> import os

>>> source(os)

You should be able to view the source of the os module.

You can also use your pythonrc.py file in Zope’s debug mode. To start up Zope’s debug mode run the following statement.

./zope/instancehome/bin/zopectl debug

On the interpreter run the following statement.

>>> execfile('/path/to/.pythonrc.py')

If you don’t like running execfile everytime you run Zope in the debug mode you could simply edit and modify

lib/python/Zope2/Startup/zopectl.py and replace the line
"import Zope2; app=Zope2.app())" with
"import Zope2; app=Zope2.app(); execfile('/home/partecs/.pythonrc.py')".

Feedburner RSS

Enter your email address:

Delivered by FeedBurner

Blogroll

Categories

RSS Telematics Freedom

March 2017
M T W T F S S
« May    
 12345
6789101112
13141516171819
20212223242526
2728293031  

Archive

Sky Sponsored by Web Hosting