小编Kri*_*rie的帖子

Python AttributeError:模块“字符串”没有属性“maketrans”

尝试在 Python 3.5.2 shell 中运行命令时收到以下错误:

Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit      
(Intel)] on win32 Type "copyright", "credits" or "license()" for more information.

>>> folder = 'C:/users/kdotz/desktop'
>>> f = open(folder + '/genesis.txt', 'r')
>>> import operator, time, string
>>> start=time.time()
>>> genesis = {}
>>> for line in f:
line=line.split()
for word in line:
    word = word.lower()
    new_word=word.translate(string.maketrans("",""), string.punctutation)
    if new_word in genesis:
        genesis[new_word]+=1
    else:
        genesis[new_word]=1
Run Code Online (Sandbox Code Playgroud)

错误:

Traceback (most recent call last):
  File "<pyshell#15>", line …
Run Code Online (Sandbox Code Playgroud)

python attributeerror python-3.x

6
推荐指数
2
解决办法
2万
查看次数

标签 统计

attributeerror ×1

python ×1

python-3.x ×1