1 |
What's the best way to send patches for the patches ;) ? |
2 |
|
3 |
For example in |
4 |
http://dev.gentoo.org/~hawking/portage-2to3/auto/11-portage-2to3-map.patch |
5 |
- there is the following hunk: |
6 |
|
7 |
<hunk> |
8 |
diff --git a/pym/portage/process.py b/pym/portage/process.py |
9 |
index f766d30..dc425af 100644 |
10 |
--- a/pym/portage/process.py |
11 |
+++ b/pym/portage/process.py |
12 |
@@ -21,7 +21,7 @@ except ImportError: |
13 |
|
14 |
if os.path.isdir("/proc/%i/fd" % os.getpid()): |
15 |
def get_open_fds(): |
16 |
- return map(int, [fd for fd in os.listdir("/proc/%i/fd" % os.getpid()) if |
17 |
fd.isdigit()]) |
18 |
+ return list(map(int, [fd for fd in os.listdir("/proc/%i/fd" % |
19 |
os.getpid()) if fd.isdigit()])) |
20 |
else: |
21 |
def get_open_fds(): |
22 |
return xrange(max_fd_limit) |
23 |
</hunk> |
24 |
|
25 |
But the complete expression could be rewritten as: |
26 |
|
27 |
return [int(fd) for fd in os.listdir("/proc/%i/fd" % os.getpid()) if |
28 |
fd.isdigit()] |
29 |
|
30 |
This is more readable - and you don't need to traverse the list multiple |
31 |
times. |
32 |
|
33 |
Alternatively - if you like the functional style more: |
34 |
|
35 |
return list(map(int, filter(str.isdigit, os.listdir("/proc/%i/fd" % |
36 |
os.getpid())))) |
37 |
|
38 |
Again more readable (if you are used to the functional style ;)) - and only |
39 |
one traversal (as iterators are used). |
40 |
|
41 |
|
42 |
/edit: I sent this mail twice, because Roundcube had chosen the wrong |
43 |
sender name and I guess, that this mail was blocked then. Excuses if you |
44 |
get the mail twice. |
45 |
|
46 |
Regards, |
47 |
Necoro |