python-实战分析windows普通日志txt
发布日期:2021-05-12 23:05:09 浏览次数:12 分类:精选文章

本文共 4844 字,大约阅读时间需要 16 分钟。

������������Windows������������

���Python���������������������

  • ���������������������

  • ���������������������������������������������������������������������������������������������Python���������������������Kali Linux������������������������������������������������

    ���������������cat������������������������������������

    cat rizhi.txt

    ���������������������������������������?.���������������������������������������������������Python���������������������codecs���������������������������������������������

    import codecs# ���������������������������with codecs.open('rizhi.txt', 'r', 'utf-8-sig') as f:    content = f.read()

    ������������������������������������������������

    1. ���������������������������������

    2. ���������������������������?.������������������������������������������������������Python���������

      import re# ������������������������������with open('rizhi.txt', 'r', encoding='utf-8') as f:    content = f.read()        # ������������������������������������    replace_pattern = re.compile(r'\?.')        # ���������������������?. ������������������������    output = replace_pattern.sub(' ', content)        # ������������������������������������    with open('rizhi_translated.txt', 'w', encoding='utf-8') as f2:        f2.write(output)

      ���������������������������rizhi_translated.txt���������������?.���������������������������

      ��������������������������������������������������������������������������������� Diff ���������������������������������������������������������

      diff rizhi.txt rizhi_translated.txt

      1. ���������������������������

      2. ���������������������������������������������������������������������Python������������������������

        import os# ������������������������log_file = 'rizhi_translated.txt'# ������������������������������list_file = 'rizhi_translated_list.csv'# ������������������������������������������if os.path.exists(log_file):    with open(log_file, 'r', encoding='utf-8') as f:        lines = f.readlines()                # ������������������������������        with open(list_file, 'w', encoding='utf-8') as f_list:            for line in lines:                # ���������������������������������                items = line.strip().split()                                # ������������������������������������������                f_list.write(f'"{��� '.join(items)}"\n')

        ���������rizhi_translated_list.csv ������������������������������������������������������������������������������������

        ������������������������������������������������������������������������������������������

        diff rizhi_translated_list.csv rizhi_translated.txt

        1. ���������������������������

        2. ������������������������������������������������������������

          • ���������������������������������������������������������������������������������������������������������������Latin-1���������������������������

          • ������������������������������������������������������������������������������������������������������Python���������������������������������������������������

          ���������������

          import sysdef process_file infile, encoding='utf-8':    with open(infile, 'r', encoding=encoding) as f:        for chunk in iter(lambda: f.read(1024), b''):            print(f'Processing chunk: {len(chunk)} bytes')if __name__ == "__main__":    for file in ['rizhi_translated.txt', 'rizhi_translated_list.csv']:        print(f'Processing file: {file}')        process_file(file)

          1. ���������������������������Excel���

          2. ������������������������������������Excel������������������������������������������������������������

            ������������������������������

            ���Excel������������������������������������������������������������������������ fileType ��� thunderclap���������������������

            ������������������Python������

            ������������������Python���������������������������������Excel������������

            import xlwt# ������������������������book = xlwt.Workbook()sheet = book.add_sheet('data')# ������������������������������������with open('rizhi_translated_list.csv', 'r', encoding='utf-8') as f:    for row, line in enumerate(f):        if row == 0:            continue  # ���������������        parts = line.strip().split(' ')        sheet.write(row-1, 0, str(parts[0]))        sheet.write(row-1, 1, str(parts[1]))        ...        book.save('data.xlsx')

            ���������������������������

          3. ���������������������������������������������������������������������������������������chardet������������������������

          4. ������������������������������������������������������������������������������������������������������������������������������

          5. ���������������������������������������������������������������������������������������������


          6. ���������������������������������������������������Windows���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

    上一篇:python-下载固定百度图片地址
    下一篇:python-列表练习程序ver2

    发表评论

    最新留言

    感谢大佬
    [***.8.128.20]2025年04月11日 22时21分58秒