以下のコードの出力:
rpl = 'This is a nicely escaped newline \\n'
my_string = 'I hope this apple is replaced with a nicely escaped string'
reg = re.compile('apple')
reg.sub( rpl, my_string )
..は:
'I hope this This is a nicely escaped newline \n is replaced with a nicely escaped string'
..印刷時:
これがうまくエスケープされた改行であることを願っています
うまくエスケープされた文字列に置き換えられます
それで、Pythonは他の文字列の「apple」を置き換えるときに文字列をエスケープ解除していますか?今のところ私はちょうどやった
reg.sub( rpl.replace('\\','\\\\'), my_string )
これは安全ですか?Pythonがそれを行うのを止める方法はありますか?