zoukankan      html  css  js  c++  java
  • 文件统计与保存

    import codecs
    """
    file = codecs.open(r"路径","rb","gbk","ignore")
    for line in file:  # 硬盘模式
        print(line)
    file.close()
    """
    def loadata():
        global datalist # 引用全局变量 把加载的内容放到全局变量中
        file = codecs.open(r"路径", "rb", "gbk", "ignore")
        datalist = file.readlines()
        file.close()
    
    
    # 保存变量
    def search(namestr):
      # 要保存文件名字和路径 savefilepath
    = "路径" + namestr +".txt" savefile = open(savefilepath,"wb") numbers = 0 for line in datalist: if line.find(namestr) != -1: print(line,end="") # 显示数据 numbers += 1 savefile.write(line.encode("utf-8")) # 写入数据 savefile.write(("数量" + str(numbers)).encode("utf-8")) savefile.close() datalist = [] print("加载开始") loadata() print("加载结束") while True: # 查询人的名字 searchname = input("要查询的数据") search(searchname)
  • 相关阅读:
    CodeForces
    EOJ 3506. 斐波那契数列
    牛客练习赛13 D幸运数字Ⅳ . 康托逆展开
    UVA
    Piggy-Bank HDU
    Dollar Dayz POJ
    UVA 674 Coin Change (完全背包)
    python OOP (1)
    python lambda简易使用
    python whl模块安装方法
  • 原文地址:https://www.cnblogs.com/wang102030/p/9273443.html
Copyright © 2011-2022 走看看