簡體   English   中英

從特定行開始追加到新文件

[英]Appending from specific line onward to new file

我想從 url 鏈接的某一行開始 append ,該鏈接是一個包含類似於以下內容的.txt 文件:
X -- Y -- Z
3 -- 5 -- 1
6 -- 4 -- 2
7 -- 2 -- 3
等等....我只設法讓它讀取所有文件並將它們附加到一個新文件中,但我想省略第一行。

import urllib.request as ur
import shutil
with ur.urlopen(#link) as link, open("#filePath", 'ab') as Data:
        shutil.copyfileobj(link, Data)

有沒有辦法將 url 到 append 中的行分割成新文件?

直接跳過第一行:

import urllib.request as ur
import shutil
with ur.urlopen(#link) as link, open("#filePath", 'ab') as Data:
    link.readline()  # Reads one line, discards it, leaves link positioned after it
                     # next(link, None) should also work; there are subtle differences,
                     # but either should work here
    shutil.copyfileobj(link, Data)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM