Re: Distinguishing between functions and methods in a decorator.

2008-02-08 Thread Berteun Damman
On Thu, 07 Feb 2008 18:22:03 +0100, Diez B. Roggisch [EMAIL PROTECTED] wrote: Can you provide an example of what you are actually after? The descriptor-protocol might come to use there. Thanks for your responses. I have read the Descriptor protocol how-to, which clarifies method access on

Distinguishing between functions and methods in a decorator.

2008-02-07 Thread Berteun Damman
Hello, I was wondering a bit about the differences between methods and functions. I have the following: def wrap(arg): print type(arg) return arg class C: def f(): pass @wrap def g(): pass def h(): pass print type(C.f) print type(h) Which gives the

Re: Unicode literals to latin-1

2008-01-30 Thread Berteun Damman
On Wed, 30 Jan 2008 09:57:55 +0100, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: How can I convert a string read from a database containing unicode literals, such as Fr\u00f8ya to the latin-1 equivalent, Frøya? I have tried variations around Fr\u00f8ya.decode('latin-1') but to no avail.

Re: Dictionary Keys question

2008-01-30 Thread Berteun Damman
On Wed, 30 Jan 2008 14:47:36 -0800 (PST), FireNWater [EMAIL PROTECTED] wrote: I'm curious why the different outputs of this code. If I make the dictionary with letters as the keys, they are not listed in the dictionary in alphabetical order, but if I use the integers then the keys are in

Re: Removal of element from list while traversing causes the next element to be skipped

2008-01-29 Thread Berteun Damman
On Tue, 29 Jan 2008 16:34:17 GMT, William McBrine [EMAIL PROTECTED] wrote: Look at this -- from Python 2.5.1: a = [1, 2, 3, 4, 5] for x in a: ... if x == 3: ... a.remove(x) ... print x ... 1 2 3 5 a [1, 2, 4, 5] You have to iterate over a copy of 'a', so for x in

Re: Removal of element from list while traversing causes the next element to be skipped

2008-01-29 Thread Berteun Damman
On Tue, 29 Jan 2008 09:23:16 -0800 (PST), [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: If you're going to delete elements from a list while iterating over it, then do it in reverse order: Why so hard? Reversing it that way creates a copy, so you might as well do: a = [ 98, 99, 100 ] for i, x

Tracking memory usage and object life time.

2007-09-26 Thread Berteun Damman
Hello, I have programmed some python script that loads a graph (the mathemical one with vertices and edges) into memory, does some transformations on it, and then tries to find shortest paths in this graph, typically several tens of thousands. This works fine. Then I made a test for this, so I

Re: Tracking memory usage and object life time.

2007-09-26 Thread Berteun Damman
On Sep 26, 2:31 pm, Bjoern Schliessmann usenet- [EMAIL PROTECTED] wrote: Did you check the return value of gc.collect? Also, try using other insight facilities provided by the gc module. gc.collect states it cannot find any unreachable objects. Meanwhile the number of objects the garbage

textwrap and combining diacritical marks

2007-06-28 Thread Berteun Damman
Hello, When using the textwrap module, the wrap will always use len() to determine the length of the string being wrapped. This might be a sensible thing to do in many circumstances, but I think there are circumstances where this does not lead to the desired result. I assume many applications of

Re: PQueue and Python 2.5

2007-01-22 Thread Berteun Damman
Gabriel Genellina wrote: Python got in 2.3 a heapq module in its standard library; I think it is what Ah! then I bet: - There is some C code involved. - It carelessly mixes PyMem_Malloc with PyObject_Free or similar as described in http://docs.python.org/whatsnew/ports.html So do yourself

PQueue and Python 2.5

2007-01-19 Thread Berteun Damman
Hello, Recently I was looking for a Priority Queue module, and I've found Pqueue by Andrew Snare [1]. When I use it with Python 2.4 everything works okay, at least on the two system I've tested it on (Debian based AMD 64) and OS PPC. However, when I use it with Python 2.5 - again on the same

Re: pyparsing and 'keywords'

2004-12-14 Thread Berteun Damman
On Tue, 14 Dec 2004 18:39:19 GMT, Paul McGuire [EMAIL PROTECTED] wrote: If I try however to parse the String if test; testagain; fi;, it does not work, because the fi is interpreted as an expr, not as the end of the if statement, and of course, adding another fi doesn't solve this either. The

pyparsing and 'keywords'

2004-12-14 Thread Berteun Damman
Hello, I'm having some problems with pyparsing, I could not find how to tell it to view certain words as keywords, i.e. not as a possible variable name (in an elegant way), for example, I have this little grammar: terminator = Literal(;) expr = Word(alphas) body = Forward(); ifstat = if + body +