• 逐行读取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)
  • 相关阅读:
    将表中数据生成SQL语句
    遍历页面所有的控件
    MSN不能登陆
    刷新框架页
    JS传参出现乱码
    iframe攻击
    有关于VS调试Javascript的问题
    C#中StringBuilder类的使用
    前瞻XAML
    Asp.Net在SqlServer中的图片存取
  • 原文地址:https://www.cnblogs.com/yaohu/p/11358701.html
Copyright © 2020-2023  润新知