回答編集履歴
3
誤記訂正
answer
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
#追記
|
5
5
|
エラー以外の部分も見ました。未定義の名前の参照の場合の処理は省いて書くと、こんな感じですかね。
|
6
6
|
```Python
|
7
|
-
|
7
|
+
import re
|
8
8
|
class tmp_Data(object):
|
9
9
|
def __init__(self):
|
10
10
|
self.host = "aaa"
|
2
補足
answer
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
`aaa = tmp_Data`→`aaa = tmp_Data()`ですね。
|
3
3
|
|
4
4
|
#追記
|
5
|
-
エラー以外の部分も見ました。
|
5
|
+
エラー以外の部分も見ました。未定義の名前の参照の場合の処理は省いて書くと、こんな感じですかね。
|
6
6
|
```Python
|
7
7
|
mport re
|
8
8
|
class tmp_Data(object):
|
1
追記
answer
CHANGED
@@ -1,2 +1,23 @@
|
|
1
1
|
このエラーの部分しか見てませんが、
|
2
|
-
`aaa = tmp_Data`→`aaa = tmp_Data()`ですね。
|
2
|
+
`aaa = tmp_Data`→`aaa = tmp_Data()`ですね。
|
3
|
+
|
4
|
+
#追記
|
5
|
+
エラー以外の部分も見ました。エラー処理は省いて書くと、こんな感じですかね。
|
6
|
+
```Python
|
7
|
+
mport re
|
8
|
+
class tmp_Data(object):
|
9
|
+
def __init__(self):
|
10
|
+
self.host = "aaa"
|
11
|
+
self.ip = "10.123.145.30"
|
12
|
+
def foo(self,match):
|
13
|
+
return self.__dict__[match.group(1).lower()]
|
14
|
+
def replace_doller(self, original):
|
15
|
+
return re.sub(r"$(.+?)$",self.foo,original)
|
16
|
+
|
17
|
+
tmp_str = "host:$HOST$\nIP:$IP$"
|
18
|
+
|
19
|
+
aaa = tmp_Data()
|
20
|
+
out = aaa.replace_doller(tmp_str)
|
21
|
+
print(tmp_str)
|
22
|
+
print(out)
|
23
|
+
```
|