gpt4 book ai didi

json - 导入错误 : cannot import name 'maketrans'

转载 作者:行者123 更新时间:2023-12-02 10:58:35 31 4
gpt4 key购买 nike

这是我的代码。不仅在此代码中,在我导入任何模块的每个代码中,ImportError: cannot import name 'package name' 都会出现

from string import maketrans

str = "geeksforgeeks"

str1 = "gfo"
str2 = "abc"

# using maktrans() to map elements of str2 with str1
mapped = maketrans(str1, str2);

# using translate() to translate using the mapping
print"The string after translation using mapped elements is : "
printstr.translate(mapped);

最佳答案

最后一行应该是

print str.translate(mapped)

不是
printstr.translate(mapped);

您能否在终端中运行此命令并发布输出
which -a python

关于json - 导入错误 : cannot import name 'maketrans' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52567910/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com