[英]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.