[英]Appending from specific line onward to new file
I want to append from a certain line onward from a url link, the link is a.txt file that contain something similar to the following:我想从 url 链接的某一行开始 append ,该链接是一个包含类似于以下内容的.txt 文件:
X -- Y -- Z X -- Y -- Z
3 -- 5 -- 1 3 -- 5 -- 1
6 -- 4 -- 2 6 -- 4 -- 2
7 -- 2 -- 3 7 -- 2 -- 3
and so forth.... I only managed to have it read all the file and appending them to a new one, but I want to omit the first line.等等....我只设法让它读取所有文件并将它们附加到一个新文件中,但我想省略第一行。
import urllib.request as ur
import shutil
with ur.urlopen(#link) as link, open("#filePath", 'ab') as Data:
shutil.copyfileobj(link, Data)
Is there a way to slice the lines within the url to append to the new file?有没有办法将 url 到 append 中的行分割成新文件?
Just skip the first line explicitly:直接跳过第一行:
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.