牛骨文教育服务平台(让学习变的简单)
博文笔记

python往某一行行尾追增内容

创建时间:2015-12-31 投稿人: 浏览次数:2305

示例:在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)
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。