我正在写一个新的应用程序在Python中,我需要保持行之间的缩进。如何保持行间的缩进?
我从一个文件中的代码:
line 1
__LINE TO CHANGE__
line 3
,我想获得:
line 1
added code line a
added code line b
line 3
我已经尝试了一些解决方案,将\ n,\ n \ r,usign “”“”“”“字符串,字符串(”“)但我只有这两个结果:我使用replace()函数来更改一行。
感谢
编辑: 我的代码:
Reading from file and put into variable named code:
line 1
__LINE TO CHANGE__
line 3
text = "added code line a"
text += "added code line b"
available_pos = ["__LINE TO CHANGE__"]
text_to_add = [text]
code = code.replace(available_pos, text_to_add)
那么你的代码在哪里? – Kasramvd 2014-10-31 20:49:38
你的意思是像使用反斜杠扩展一行代码? – smoothgrips 2014-10-31 20:50:06
''foo“.replace(”foo“,”“+”foo“)' – 2014-10-31 20:52:50