zoukankan      html  css  js  c++  java
  • 逐行读取txt文件,分割,写入txt。。。上传,下载

    = []

    f  = open('querylist.txt','r'#由于我使用的pycharm已经设置完了路径,因此我直接写了文件名
    for lines in f:
        ls = lines.strip(' ').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+' ')
    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)
  • 相关阅读:
    MongoDB学习笔记(二)
    mongoDB学习笔记(一)
    docker官方文档笔记
    nagios
    网络流量状态命令总结 (含notp安装)
    other
    一键搭建LNMP脚本
    linux问题总结
    linux中VI编写C程序。。。
    centos 7 安装python3.5.1
  • 原文地址:https://www.cnblogs.com/yaohu/p/11358701.html
Copyright © 2011-2022 走看看