在Python中,当给定文本文件的URL时,从文本文件中访问内容并在不保存文本文件的本地副本的情况下逐行本地打印文件内容的最简单方法是什么?
TargetURL=http://www.myhost.com/SomeFile.txt
#read the file
#print first line
#print second line
#etc
Run Code Online (Sandbox Code Playgroud) 我有一个 312 MB 的 pkl 文件。我想将其存储到外部服务器 (S3) 或文件存储服务(例如 Google Drive、Dropbox 或任何其他服务)。当我运行模型时,应该从该外部 URL 加载 pkl 文件。我已经查看了这篇文章,但无法使其发挥作用。
代码:
import urllib
import pickle
Nu_SVC_classifier = pickle.load(urllib.request.urlopen("https://drive.google.com/open?id=1M7Dt7CpEOtjWdHv_wLNZdkHw5Fxn83vW","rb"))
Run Code Online (Sandbox Code Playgroud)
错误:
类型错误:POST 数据应该是字节、字节的可迭代对象或文件对象。它不能是 str 类型。