sorted or .sort() ?

2008-06-16 Thread Peter Bengtsson
My poor understanding is that the difference between `sorted(somelist, key=lambda x:...)` and `somelist.sort(lambda x,y...)` is that one returns a new list and the other sorts in-place. Does that mean that .sort() is more efficient and should be favored when you can (i.e. when you don't mind chang

Re: mocking a logging object

2008-06-02 Thread Peter Bengtsson
On Jun 2, 12:34 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Peter Bengtsson wrote: > > In my unittest I want to override the logger of a working module so > > that it puts all logging messages in /tmp/test.log instead so that in > > my unittest I can

Re: mocking a logging object

2008-06-02 Thread Peter Bengtsson
On Jun 2, 12:34 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Peter Bengtsson wrote: > > In my unittest I want to override the logger of a working module so > > that it puts all logging messages in /tmp/test.log instead so that in > > my unittest I can

mocking a logging object

2008-06-02 Thread Peter Bengtsson
In my unittest I want to override the logger of a working module so that it puts all logging messages in /tmp/test.log instead so that in my unittest I can inspect that it logs things correctly. Hopefully this "pseudo" code will explain my problem:: >>> import logging, os >>> logging.basicConfig(f

Re: ElementTree and namespaces in the header only

2008-01-16 Thread Peter Bengtsson
On Jan 15, 5:22 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Peter Bengtsson wrote: > > root = Element('feed', xmlns='http://www.w3.org/2005/Atom') > > root.set('xmlns:se', NS_URL) > > entry = SubElement(root, 'entry') >

ElementTree and namespaces in the header only

2008-01-15 Thread Peter Bengtsson
Here's my code (simplified): NS_URL = 'http://www.snapexpense.com/atom_ns#' ElementTree._namespace_map[NS_URL] = 'se' def SEN(tag): return "{%s}%s" % (NS_URL, tag) root = Element('feed', xmlns='http://www.w3.org/2005/Atom') root.set('xmlns:se', NS_URL) entry = SubElement(root, 'entry') SubEle

Re: Normalize a polish L

2007-10-16 Thread Peter Bengtsson
On Oct 15, 10:57 pm, John Machin <[EMAIL PROTECTED]> wrote: > On Oct 16, 2:33 am, Peter Bengtsson <[EMAIL PROTECTED]> wrote: > > > > > In UTF8, \u0141 is a capital L with a little dash through it as can be > > seen in this image:http://static.peterbe.com/luka

Re: Setting a timeout for a cookie

2007-10-15 Thread Peter Bengtsson
On Oct 15, 4:09 pm, sophie_newbie <[EMAIL PROTECTED]> wrote: > Hi, > > I'm wondering how do you set a 'timeout' or expiry date/time for a > cookie set using a python cgi script. I can set a cookie ok but I > dunno how to set the expiry time so it always expires at the end of > the session. > Easy,

Normalize a polish L

2007-10-15 Thread Peter Bengtsson
In UTF8, \u0141 is a capital L with a little dash through it as can be seen in this image: http://static.peterbe.com/lukasz.png I tried this: >>> import unicodedata >>> unicodedata.normalize('NFKD', u'\u0141').encode('ascii','ignore') '' I was hoping it would convert it it 'L' because that's what

Re: Pickling a class with a __getattr__

2007-04-01 Thread Peter Bengtsson
On Apr 1, 5:48 pm, Peter Otten <[EMAIL PROTECTED]> wrote: > Peter Bengtsson wrote: > > Hi, I'm trying to pickle an object instance of a class that is like a > > dict but with a __getattr__ and I'm getting pickling errors. > > This is what happens when I&#

Pickling a class with a __getattr__

2007-04-01 Thread Peter Bengtsson
Hi, I'm trying to pickle an object instance of a class that is like a dict but with a __getattr__ and I'm getting pickling errors. This works but is not good enough. $ python2.4 >>> import cPickle as pickle >>> class Dict(dict): ... pass ... >>> >>> >>> friend = Dict(name='Zahid', age=40) >>>

Re: Finding non ascii characters in a set of files

2007-02-23 Thread Peter Bengtsson
On Feb 23, 2:38 pm, [EMAIL PROTECTED] wrote: > Hi, > > I'm updating my program to Python 2.5, but I keep running into > encoding problems. I have no ecodings defined at the start of any of > my scripts. What I'd like to do is scan a directory and list all the > files in it that contain a non ascii

With PIL... paste image on top of other with dropshadow

2007-02-23 Thread Peter Bengtsson
I love the dropshadow effect I managed to make with this recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/474116 Here's what it can look like: http://www.peterbe.com/test/188-tequilacat.2.jpg It takes a background as a parameter but it's just a colour. What I want is to put the ima

Re: Squezing in replacements into strings

2005-04-25 Thread Peter Bengtsson
tle() > ... > >>> re.compile("(peter)", re.I).sub(process, "Peter Bengtsson PETER, or > PeTeR") > '_Peter_ Bengtsson _Peter_, or _Peter_' > >>> Ahaa! Great. I didn't realise that I can substitute with a callable that gets the match object. Hadn't thought of it that way. Will try this now. -- http://mail.python.org/mailman/listinfo/python-list

Squezing in replacements into strings

2005-04-25 Thread Peter Bengtsson
I've got a regular expression that finds certain words from a longer string. >From "Peter Bengtsson PETER, or PeTeR" it finds: 'Peter','PETER','PeTeR'. What I then want to do is something like this: def _ok(matchobject): # more complicated