Python 如何从路径文件夹服务器本地下载文件。非URL
my_python.pyPython 如何从路径文件夹服务器本地下载文件。非URL,python,Python,my_python.py import urllib2 filedata = urllib2.urlopen('D:/python/uploadRM/app/file/myfile.pdf') #from local directory not url datatowrite = filedata.read() 与open()一起使用可从计算机读取文件 with open("D:/python/uploadRM/app/file/myfile.pdf") as myFile:
import urllib2
filedata = urllib2.urlopen('D:/python/uploadRM/app/file/myfile.pdf') #from local directory not url
datatowrite = filedata.read()
与open()一起使用可从计算机读取文件
with open("D:/python/uploadRM/app/file/myfile.pdf") as myFile:
#rest of your code
不确定为什么要使用
urlopen()
打开本地文件,但可以尝试使用文件://
HTTP方案:
import urllib2
filedata = urllib2.urlopen('file:///D:/python/uploadRM/app/file/myfile.pdf')
datatowrite = filedata.read()
通常,最好使用open()
将其作为普通文件打开:
with open('D:/python/uploadRM/app/file/myfile.pdf') as f:
datatowrite = f.read()
请不要在问题中添加随机标记。