打开:模式或文件名无效

2024-09-28 23:39:53 发布

您现在位置:Python中文网/ 问答频道 /正文

这是字数统计程序。怎么能让它变得更简单呢?在

import re
from collections import Counter

with open('C:\Data\test.txt') as f:
passage = f.read()

words = re.findall(r'\w+', passage)

cap_words = [word.upper() for word in words]

word_counts = Counter(cap_words)

继续获取此错误消息:

^{pr2}$

Tags: fromtestimport程序redatawithcounter