回答編集履歴
2
追記
test
CHANGED
File without changes
|
1
追記
test
CHANGED
@@ -4,15 +4,11 @@
|
|
4
4
|
|
5
5
|
```Python
|
6
6
|
|
7
|
-
import re
|
8
|
-
|
9
|
-
|
10
|
-
|
11
7
|
tes = "__cd='d40000', ipip='2769419', dhash='3925fd', ss='dzze', eve='15671'"
|
12
8
|
|
13
9
|
|
14
10
|
|
15
|
-
l = re.findall( r"(.+?)\='(.*?)'\s*,*", tes)
|
11
|
+
l = re.findall( r"(.+?)\=\s*'(.*?)'\s*,*", tes)
|
16
12
|
|
17
13
|
|
18
14
|
|
@@ -21,3 +17,21 @@
|
|
21
17
|
print(ret) # {'__cd': 'd40000', 'ipip': '2769419', 'dhash': '3925fd', 'ss': 'dzze', 'eve': '15671'}
|
22
18
|
|
23
19
|
```
|
20
|
+
|
21
|
+
### 追記
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
なお、辞書のキーと値を変数とその値として定義するには以下のようにすればよいです。
|
26
|
+
|
27
|
+
参考:[convert dictionary entries into variables - python](https://stackoverflow.com/questions/18090672/convert-dictionary-entries-into-variables-python)
|
28
|
+
|
29
|
+
```Python
|
30
|
+
|
31
|
+
# 辞書→変数に
|
32
|
+
|
33
|
+
locals().update(ret)
|
34
|
+
|
35
|
+
print(__cd) # d40000
|
36
|
+
|
37
|
+
```
|