s
=
[]
f
=
open
(
'querylist.txt'
,
'r'
)
#由于我使用的pycharm已经设置完了路径,因此我直接写了文件名
for
lines
in
f:
ls
=
lines.strip(
'
'
).replace(
' '
,'
').replace('
、
','
/
').replace('
?
','
').split('
/
')
for
i
in
ls:
s.append(i)
f.close()
print
(s)
===============================
f1
=
open
(
'query_result.txt'
,
'w'
)
for
j
in
s:
f1.write(j
+
'
'
)
f1.close()
=========================================
import requests import os #上传文件到服务器 file = {'file': open('hello.txt','rb')} r = requests.post('http://127.0.0.1:8000/upload', files=file) print(r.text) #查询fpath下的所有文件 r1 = requests.get('http://127.0.0.1:8000/getfiles',data={'fpath': r'download/'}) print(r1.text) #下载服务器download目录下的指定文件 r2 = requests.get('http://127.0.0.1:8000/download',data={'filename':'hello_upload.txt', 'path': r'upload/'}) file = r2.text #获取文件内容 basepath = os.path.join(os.path.dirname(__file__), r'download/') with open(os.path.join(basepath, 'hello_download.txt'),'w',encoding='utf-8') as f: #保存文件 f.write(file)