import zipfile
import re
# 压缩包路径和密码
zip_path = 'archive.zip'
password = ''
# 要查找的中文词
target_words = ['词1', '词2']
# 正则表达式模式,用于匹配中文
chinese_pattern = re.compile('[\u4e00-\u9fa5]+')
# 打开压缩包
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
# 解压文件
for filename in zip_ref.namelist():
if filename.endswith('.txt'):
# 读取TXT文件内容
with zip_ref.open(filename) as file:
content = file.read().decode('utf-8')
# 在文件内容中查找匹配的中文词
for target_word in target_words:
matches = chinese_pattern.findall(content)
if matches:
print(f"Found '{target_
import zipfile
import re
# 压缩包路径和密码
zip_path = 'archive.zip'
password = ''
# 要查找的中文词
target_words = ['词1', '词2']
# 正则表达式模式,用于匹配中文
chinese_pattern = re.compile('[\u4e00-\u9fa5]+')
# 打开压缩包
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
# 解压文件
for filename in zip_ref.namelist():
if filename.endswith('.txt'):
# 读取TXT文件内容
with zip_ref.open(filename) as file:
content = file.read().decode('utf-8')
# 在文件内容中查找匹配的中文词
for target_word in target_words:
matches = chinese_pattern.findall(content)
if matches:
print(f"Found '{target_word}' in file '{filename}': {matches}")
word}' in file '{filename}': {matches}")
import zipfile
import re
# 压缩包路径和密码
zip_path = 'archive.zip'
password = ''
# 要查找的中文词
target_words = ['词1', '词2']
# 正则表达式模式,用于匹配中文
chinese_pattern = re.compile('[\u4e00-\u9fa5]+')
# 打开压缩包
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
# 解压文件
total_word_count = 0 # 用于记录目标词的总数
for filename in zip_ref.namelist():
if filename.endswith('.txt'):
# 读取TXT文件内容
with zip_ref.open(filename) as file:
content = file.read().decode('utf-8')
# 在文件内容中查找匹配的中文词
for target_word in target_words:
matches = chinese_pattern.findall(content)
if matches:
total_word_count += len(matches) # 增加目标词的总数
print(f"Found '{target_word}' in file '{filename}': {matches}")
print(f"Total count for '{target_words[0]}' and '{target_words[1]}' in archive: {total_word_count}")
import zipfile
import re
# 压缩包路径和密码
zip_path = 'archive.zip'
password = ''
# 要查找的中文词
target_words = ['词1', '词2']
# 正则表达式模式,用于匹配中文
chinese_pattern = re.compile('[\u4e00-\u9fa5]+')
# 打开压缩包
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
# 解压文件
total_word_count = 0 # 用于记录目标词的总数
for filename in zip_ref.namelist():
if filename.endswith('.txt'):
# 读取TXT文件内容
with zip_ref.open(filename) as file:
content = file.read().decode('utf-8')
# 在文件内容中查找匹配的中文词
for target_word in target_words:
matches = chinese_pattern.findall(content)
if matches:
total_word_count += len(matches) # 增加目标词的总数
print(f"Found '{target_word}' in file '{filename}': {matches}")
print(f"Total count for '{target_words[0]}' and '{target_words[1]}' in archive: {total_word_count}")