1 |
Le 14/02/2015 20:03, Anthony G. Basile a écrit : |
2 |
> |
3 |
|
4 |
In the last chunk of modules/generic_stage_target.py: |
5 |
|
6 |
* type(var) == types.DictType can be replaced with |
7 |
isinstance(var, dict). |
8 |
|
9 |
Same thing for StringType/str, ListType/list and BooleanType/bool. |
10 |
This is how simple types were checked before Python 2.2 (around 2002). |
11 |
|
12 |
* string.replace has been deprecated for ages, use str.replace directly: |
13 |
|
14 |
varname2="clst_"+string.replace(y,"/","_") |
15 |
varname2=string.replace(varname2,"-","_") |
16 |
varname2=string.replace(varname2,".","_") |
17 |
|
18 |
becomes |
19 |
|
20 |
varname2 = "clst_" + y.replace("/", "_") |
21 |
varname2 = varname2.replace("-", "_") |
22 |
varname2 = varname2.replace(".", "_") |
23 |
|
24 |
* string.join is also deprecated, use ' '.join() instead |
25 |
|
26 |
* dict objects are iterable (and they return keys). This means that |
27 |
|
28 |
string.join(self.settings[x].keys()) |
29 |
|
30 |
can be written (with the join suggestion above): |
31 |
|
32 |
' '.join(self.settings[x]) |
33 |
|
34 |
* You may want to use dict.items() to get both the key and the |
35 |
associated value: |
36 |
|
37 |
for y in self.settings[x].keys(): |
38 |
|
39 |
becomes: |
40 |
|
41 |
for y, val in self.settings[x].items(): |
42 |
|
43 |
which should allow you to replace "self.settings[x][y]" with "val" |
44 |
|
45 |
Cheers, |
46 |
|
47 |
Rémi |