
本文共 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()
������������������������������������������������
- ���������������������������������
- ���������������������������
- ���������������������������
���������������������������������������������������������������������������������������������������������������Latin-1���������������������������
������������������������������������������������������������������������������������������������������Python���������������������������������������������������
- ���������������������������Excel���
���������������������������������������������������������������������������������������
chardet
������������������������������������������������������������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������
���������������������������?.
������������������������������������������������������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
���������������������������������������������������������������������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
������������������������������������������������������������
���������������
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)
������������������������������������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')
���������������������������
���������������������������������������������������Windows���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
