Python:为什么replace function和for循环在我的程序上表现得很奇怪?

2024-09-27 19:30:36 发布

您现在位置:Python中文网/ 问答频道 /正文

matcher = re.compile(r"hklay1\s+(.*?)\s+kppt1", re.DOTALL)
for i in xrange(1, 5):  
    with open("data{}.txt".format(i), "r") as f:  
        with open("nwirp{}.upw".format(i), "r") as f2:
            with open("data{}.upw".format(i), "w") as out:
                    content = matcher.findall(f.read()) 
                    print content
                    for line in f2:
                        lines = line.replace('5.0472640E-03', 'content')
                        out.write("".join(lines)) 

写入文件中的内容应该是数字,但内容变成这样的内容

UPW:ModelMuse版本3.6.2.0于2016年4月12日创建的上游加权包文件

创建于模型工具.py你知道吗

第2行

9-8.8880000000E+003 0#数据集1,IUPWCB HDRY NPUPW IPHDRY
10#铺设类型
10层平均值
-1-1#通道
1 1#拉伊夫卡
0 0#湿铺
内部1.0(免费)12#HK第1层第1层
内容 内容 内容 内容 内容 内容 内容 内容 内容 内容 内容 内容 内容

谁能告诉我这里有什么问题吗?你知道吗


Tags: inreformat内容fordataaswith

热门问题