我的一个模块 (t_mesg.py) 有一个多行字符串:
tm = """
this
is currently
a
test
message
"""
我将它导入到另一个模块中,我需要将字符串的某些部分替换为其他部分。但是,在导入时,换行符也会出现,因此tm.replace(...)不起作用。
>>> from t_mesg import tm
>>> tm
'\nthis\nis \na\ntest\nmessage\n'
如果我需要处理这个导入的字符串以将“是”更改为“不是”,我将如何处理,使字符串看起来像这样?
tm = """
this
is not currently
a
test
message
"""
TL; DR - 如何在忽略换行符的情况下执行替换?
莫回无
相关分类