python -修改文件中某一行


写代码写错了顺序,所以想办法把x,y坐标调换回来

def change_ptsxy(fileName):
    fp = open(fileName)
    i = 0
    file_data = ""
    for line in fp.xreadlines():
        # print line.strip("\n")
        TT = line.strip("\n")
        if i > 2 and i < 71:
            # print TT
            TT_temp = TT.split(" ")
            x = int(float(TT_temp[0]))
            y = int(float(TT_temp[1].strip("\r")))
            old_str=str(x)+" "+str(y)
            new_str=str(y)+" "+str(x)
            # print(new_str)
            line = line.replace(old_str, new_str)
            file_data += line
            # print(file_data)
        else:
            file_data += line
        i += 1
    fp = open(fileName, 'w+')

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM