日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python怎么转到下一行_Python转到下一行并保存/编辑内容

發布時間:2025/3/11 python 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python怎么转到下一行_Python转到下一行并保存/编辑内容 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這個代碼是在以前的帖子中建立的。我正在努力調整它以適應我們的數據。但這不管用。。以下是我們的文件示例:read:1424:2165 TGACCA/1:2165 TGACCA/2

1..100 +chr1:3033296..3033395 #just this line

1..100 -chr1:3127494..3127395

1..100 +chr1:3740372..3740471

1 concordant read:1483:2172 TGACCA/1:2172 TGACCA/2

1..100 -chr7:94887644..94887545 #and just this line

該代碼應執行以下操作:搜索每一行

識別字符串“read:”

轉到下一行并提取+chr:編號..編號'

就一次!然后搜索下一個“read:”等。。。在

所以,如果我在“讀”之后多次出現“-chr:no..no”,那么只需要第一個。在

不幸的是,我不知道該怎么做。。。在

^{pr2}$

輸出應該如下所示:1 3033293 3033395

7 94887644 94887545

有人扔給我一根骨頭

根據以下答案更新

好吧,我上傳了一個我用過的Tim McNamara的稍作修改的版本。它工作得很好,但是輸出不能識別“chr”后面有兩個數字的數字,并在最后一個數字之后打印一個字符串with open(infile, mode='r') as in_f, open(outfile, mode='w') as out_f:

lines = [line for line in in_f.readlines()]

for i, line in enumerate(lines):

if 'read' in line:

data = lines[i+1].replace(':', '..').split('..')

try:

out_f.write('{} {} {}\n'.format(data[1][-1], data[2], data[3])) #Here I tried to remove data[3] to avoid to have "start" in the output file.. didn't work ..

except IndexError:

continue

以下是使用此代碼獲得的輸出:6 140302505 140302604 start # 'start' is a string in our data after this number

5 46605561 46605462 start # I don't understand why it grabs it thou...

5 46605423 46605522 start # I tried to modify the code to avoid this, but ... didn't work out

6 29908310 29908409 start

6 29908462 29908363 start

4 12712132 12712231 start

我怎樣才能修正這兩個錯誤?在

總結

以上是生活随笔為你收集整理的python怎么转到下一行_Python转到下一行并保存/编辑内容的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。