One of my modules (t_mesg.py) has a multi-line string:
tm = """
this
is currently
a
test
message
"""
I import this in another module where I would need to replace certain parts of the string with others. However, on the import, the newline chars come in as well and so tm.replace(...) would not work.
>>> from t_mesg import tm
>>> tm
'\nthis\nis \na\ntest\nmessage\n'
If I need to process this imported string to change "is" to "is not" how would I go about it, so that the string looks like this?
tm = """
this
is not currently
a
test
message
"""
TL;DR - how can I perform the replacement ignoring the newline chars?
print(tm)tm.replace('\nis \n', '\nis not\n')works fine for me. Of course, it doesn't modifytm, since strings are immutable. If you want to changetm, you needtm = tm.replace('\nis \n', '\nis not\n')