逐行读取txt文件,分割,写入txt。。。上传,下载

= []

f  = open('querylist.txt','r'#由于我使用的pycharm已经设置完了路径,因此我直接写了文件名
for lines in f:
    ls = lines.strip('\n').replace(' ','').replace('','/').replace('?','').split('/')
    for in ls:
        s.append(i)
f.close()
print(s)
===============================
f1 = open('query_result.txt','w')
for in s:
    f1.write(j+'\n')
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)

 

posted @ 2019-08-15 16:21  千年妖狐  阅读(586)  评论(0编辑  收藏  举报