私はいくつかのjsonを返す次のコードを用意しています。出力を.subample.comに変更したい。通常はawkでこれを行うことができますが、この特殊なケースではPythonで処理する必要があります。Pythonの文字列代入
私がやっていることは、リテラル文字列 'example.com'を 'sub.example.com'に置き換えることです。 IPビット作品アウトフィルタリングが、私はちょうどより簡単一部:(どうあるべきかを把握することはできません。
def filterIP(fullList):
regexIP = re.compile(r'\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$')
return filter(lambda i: not regexIP.search(i), fullList)
def filterSub(fullList2):
regexSub = re.recompile('example.com', 'sub.example.com', fullList2)
groups = {key : filterSub(filterIP(list(set(items)))) for (key, items) in groups.iteritems() }
print(self.json_format_dict(groups, pretty=True))
"role_1": [
"type-1.example.com",
"type-12-sfsdf-453-2.example.com"
]
正規表現で '.'をエスケープする必要があります。 – Barmar
're.recompile'関数はありません。 – Barmar
're.sub()'を呼び出さない – Barmar