小编Gui*_*uan的帖子

python:替换替换错误的行的位置

我有原线:
2.48724e-008 0.00022974 0.65 1 4 0 0 0.0002 2 2 2 0
我要新线:
6.1054382342e-10 1.26357e-05 0.65 1 4 0 0 1.1e-05 2 2 2 0

码:

replacement = {'2.48724e-008':'6.1054382342e-10','0.00022974':'1.26357e-05','0.0002':'1.1e-05')}
for src, target in replacement.iteritems():
      line = line.replace(src,target)
Run Code Online (Sandbox Code Playgroud)

但结果是:
6.1054382342e-10 1.1e-052974 0.65 1 4 0 0 1.1e-05 2 2 2 0

第二个数字是错误的.好像python在原始行中找到了"0.0002",并将其替换为"1.1e-05",无论它是什么.

你能帮我解决这个问题吗?

python replace python-2.7

4
推荐指数
1
解决办法
113
查看次数

标签 统计

python ×1

python-2.7 ×1

replace ×1