python往某一行行尾追增内容
示例:在PATH开头的这一行末尾添加/usr/local/mysql/bin
with open("/home/mysql/.bash_profile") as f:
lines=f.readlines()with open("/home/mysql/.bash_profile","w") as w:
for l in lines:
if(l.startswith("PATH")):
w.write(l.replace(b" ",b":/usr/local/mysql/bin "))
else:
w.write(l)
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: python在文本开头插入一行
- 下一篇: Python:字符串中指定位置插入一个字符