-4

我有这个 rs.txt 文件,其中包含:

rs41453844=CT rs36005134=AT rs41518851=AG rs2287980=GT rs28526632=AG rs41342447=AG rs41367249=AG (312, 0.207447)

rs41453844=CT rs36005134=AT rs41518851=AG rs2287980=GT rs28526632=AG rs41342447=AG rs41444944=AG (310, 0.206117)

rs41453844=CT rs36005134=AT rs41518851=AG rs2287980=GT rs28526632=AG rs41342447=AG (422, 0.280585)

rs41453844=CT rs36005134=AT rs41518851=AG rs2287980=GT rs28526632=AG rs41483646=AG (384, 0.255319)

rs41453844=CT rs36005134=AT rs41518851=AG rs2287980=GT rs28526632=AG rs41369844=AG rs235633=CT (301, 0.200133)

rs41453844=CT rs36005134=AT rs41518851=AG rs2287980=GT rs28526632=AG rs41369844=AG (396, 0.263298)

rs41453844=CT rs36005134=AT rs41518851=AG rs2287980=GT rs28526632=AG rs41440845=CT (384, 0.255319)

谁能帮我用python代码删除括号中的数字?我只想将 rs# 保存在一个新的 .txt 文件中。谢谢。

4

1 回答 1

0

怎么样

line = line.split("(")[0]

(第一个(字符之前的所有内容)

所以你的程序就像

with open("rs.txt") as inf, open("new.txt", "w") as outf:
    for line in inf:
        line = line.split("(", 1)[0].rstrip() + "\n"
        outf.write(line)
于 2014-04-21T02:40:29.443 回答