首页 > 其他分享 >分类处理获取到的数据

分类处理获取到的数据

时间:2024-02-28 18:33:23浏览次数:13  
标签:utf encoding 处理 分类 获取 file strip txt open

# !/usr/bin/env python
# -*- coding:utf-8 -*-

"""
# File       : XXXXsjfl.py
# Time       :2023/9/1 20:15
# Author     :lrtao2010
# version    :python 3.10.1
# Description:分类处理获取到的数据
"""



file_name = './shuju/shareholder.txt'
file_count = './shuju/XXXX-tj.txt'
file_add = './shuju/shareholder-add.txt'
file_new = './shuju/shareholder-new.txt'
file_unchanged = './shuju/shareholder-un.txt'
file_list = [f"{file_add}",f"{file_new}",f"{file_unchanged}"]



def classify(file_name):
    print("文件处理程序正在运行...")
    #对信息进行分类处理
    with open(file_name, encoding='utf-8')as f:
        for i in f.readlines():
            if i.strip().endswith("增加"):
                with open(file_add, 'a+', encoding='utf-8')as s_f:
                    s_f.write(f"{i.strip()}" + "\n")
            elif i.strip().endswith("新进"):
                with open(file_new, 'a+', encoding='utf-8')as s_f:
                    s_f.write(f"{i.strip()}" + "\n")
            else:
                with open(file_unchanged, 'a+', encoding='utf-8')as s_f:
                    s_f.write(f"{i.strip()}" + "\n")

    #统计次数并记录
    with open(file_count,'r',encoding='utf-8') as c_f:
        for file_str in c_f.readlines():
            file_str = file_str.strip()
            for i_file in file_list:
                with open(i_file,'r', encoding='utf-8')as i_f_r:
                    counts = 0
                    for line in i_f_r.readlines():
                        time = line.count(file_str)
                        counts += time
                    if counts != 0:
                        with open(i_file, 'a+', encoding='utf-8')as i_f_a:
                            i_f_a.write(f"{file_str}" + " " + f"{counts}" + "\n" )


    print("文件处理完成")

if __name__ == '__main__':
    classify(file_name)

 

标签:utf,encoding,处理,分类,获取,file,strip,txt,open
From: https://www.cnblogs.com/lrtao2010/p/18041409

相关文章

  • Photoshop学友:AI图片处理与高清视频教程的完美结合
    Photoshop学友:AI图片处理与高清视频教程的完美结合 在数字艺术日益盛行的今天,Photoshop学友作为一款独特的软件,凭借其AI图片处理功能和免费高清视频教程的完美结合,为用户提供了一个全面的学习与实践平台。 限时免费,PhotoShop学友电脑版软件免费下载使用下载地址:http://p......
  • C++的异常处理究竟有多慢?
    我们能在各处看到“C++的异常很慢,不要用”这样的言论,不过很少有人告诉你,C++的异常到底有多慢,以及它为什么这么慢。本文会详细介绍C++在抛出以及捕获异常时,代码到底做了什么,以及我们使用C++异常到底付出了多少代价。抛出异常要了解异常处理到底做了什么,我们需要深入到汇编语言来......
  • 获取日期
    function输出当前日期和时间(){constnow=newDate();constyear=now.getFullYear();//年constmonth=now.getMonth()+1;//月份(0-11,加1得到1-12)constday=now.getDate();//日期consthour=now.getHours();//小时(0-23)......
  • 反射获取注解,框架的基础
        packageaaa;importjava.lang.annotation.*;importjava.lang.reflect.Field;publicclasstest{publicstaticvoidmain(String[]args)throwsClassNotFoundException{Class<?>u1=Class.forName("aaa.User");......
  • C#的List分批数据处理
    1.直接贴代码块List的扩展publicstaticclassListExtension{///<summary>///分页数据///</summary>///<typeparamname="T"></typeparam>///<paramname="source">数据源</param>///......
  • 统一异常处理@ControllerAdvice及参数校验@Validated
    一、异常处理有异常就必须处理,通常会在方法后面throws异常,或者是在方法内部进行trycatch处理。直接throwsException直接throwsException,抛的异常太过宽泛,最好能抛出准确的异常,比如throwsIOException之类。UsergetUserById(Integerid)throwsIOException,BusinessE......
  • 解决HttpServletRequest调用getInputStream()方法读取参数只能获取一次问题
    1、问题描述由于后端接口获取前端传过的参数是通过HttpServletRequest接收获取的。现有一需求需要在接口调用之前拦截接口进行业务处理。在拦截类中调用getInputStream()获取参数之后,在接口方法里获取参数为空。2、解决方法自定义一个过滤器过滤所有请求,使用HttpServletRequest......
  • Vue 2x 系列之(七)事件处理
    事件处理1.事件的基本使用模板只能用到对应Vue实例中的数据和方法,像这里的showInfo,模板中是调不到的所有被Vue管理的函数【methods对象中的函数】不能写成箭头函数,只能写成普通函数,否则,函数中的this就不再是Vue实例,而是Window对象只有配置在data中的内容才会做数据代理和数......
  • Java获取客户端IP地址进行记录
    1、编写工具类IpUtilspublicclassIpUtils{/***访问IP:0:0:0:0:0:0:0:1*访问IP:192.168.1.10*/privatestaticfinalStringIP_UTILS_FLAG=",";privatestaticfinalStringUNKNOWN="unknown";privatestati......
  • python-获取当前目录路径的几个方法
     1、fromos.pathimportabspath,dirnameprint(abspath(__file__))__file__ 是一个特殊的变量,它表示当前脚本的文件名(带有路径)。abspath() 是一个函数,它返回指定文件或目录的绝对路径。因此,这行代码将打印出当前脚本的绝对路径。print(dirname(abspath(__file__)......