rdiff-backup-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [rdiff-backup-users] rdiff-backup-statistics still depends onPython


From: roland
Subject: Re: [rdiff-backup-users] rdiff-backup-statistics still depends onPython 2.4
Date: Sat, 11 Nov 2006 21:43:43 +0100

Is the following going to be fixed any time soon? rdiff-backup rocks!
(And it would be nice to see how the repository is changing in more
depth)

unfortunately i`m no programmer and unfortunately i don`t understand those "lambda x,y..." example - but maybe someone with some python/programming knowledge can investigate into this with some help from http://www.python.org/doc/2.4.4/whatsnew/node12.html :

Three keyword parameters, cmp, key, and reverse, were added to the sort() method of lists. These parameters make some common usages of sort() simpler. All of these parameters are optional. For the cmp parameter, the value should be a comparison function that takes two parameters and returns -1, 0, or +1 depending on how the parameters compare. This function will then be used to sort the list. Previously this was the only parameter that could be provided to sort().

key should be a single-parameter function that takes a list element and returns a comparison key for the element. The list is then sorted using the comparison keys. The following example sorts a list case-insensitively:


L = ['A', 'b', 'c', 'D']
L.sort()                 # Case-sensitive sort
L
['A', 'D', 'b', 'c']
# Using 'key' parameter to sort list
L.sort(key=lambda x: x.lower())
L
['A', 'b', 'c', 'D']
# Old-fashioned way
L.sort(cmp=lambda x,y: cmp(x.lower(), y.lower()))
L
['A', 'b', 'c', 'D']
The last example, which uses the cmp parameter, is the old way to perform a case-insensitive sort. It works but is slower than using a key parameter. Using key calls lower() method once for each element in the list while using cmp will call it twice for each comparison, so using key saves on invocations of the lower() method.

For simple key functions and comparison functions, it is often possible to avoid a lambda expression by using an unbound method instead. For example, the above case-insensitive sort is best written as:


L.sort(key=str.lower)
L
['A', 'b', 'c', 'D']
Finally, the reverse parameter takes a Boolean value. If the value is true, the list will be sorted into reverse order. Instead of L.sort() ; L.reverse(), you can now write L.sort(reverse=True).

The results of sorting are now guaranteed to be stable. This means that two entries with equal keys will be returned in the same order as they were input. For example, you can sort a list of people by name, and then sort the list by age, resulting in a list sorted by age where people with the same age are in name-sorted order.

(All changes to sort() contributed by Raymond Hettinger.)







----- Original Message ----- From: "Tim" <address@hidden>
To: <address@hidden>
Sent: Saturday, November 11, 2006 2:04 AM
Subject: [rdiff-backup-users] rdiff-backup-statistics still depends onPython 2.4


Is the following going to be fixed any time soon? rdiff-backup rocks!
(And it would be nice to see how the repository is changing in more
depth)

Thanks

Tim
p.s. I'm not subscribed to the list, so please CC me.
---
From: Ben Escoto
Subject: Re: [rdiff-backup-users] rdiff-backup-statistics not working
Date: Sun, 29 Jan 2006 16:02:48 -0600

Martin Kos <address@hidden>
wrote the following on Tue, 24 Jan 2006 17:07:53 +0100

     incs.sort(key = lambda i: i.getinctime())
TypeError: sort() takes no keyword arguments

any idea on this one? thanks

Looks like I was using a feature that was introduced in python v2.4.  I
should probably go back and change that, since I believe the rest of
rdiff-backup only needs python v2.2 or later.

--
Linux Counter user #273956
Don't email address@hidden


_______________________________________________
rdiff-backup-users mailing list at address@hidden
http://lists.nongnu.org/mailman/listinfo/rdiff-backup-users
Wiki URL: http://rdiff-backup.solutionsfirst.com.au/index.php/RdiffBackupWiki





reply via email to

[Prev in Thread] Current Thread [Next in Thread]