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

标签 json python-2.7 compiler-errors

这是我的代码。不仅在此代码中,在我导入任何模块的每个代码中,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/

相关文章:

python - 抑制子进程的输出

javascript - JSON 解析 - 名称内的单引号

Java:向方法传递多个参数

python-2.7 - 使用 Python Tweepy 搜索术语交集和并集

将plt文件转换为特定格式的gcode的Python代码

arrays - 没有收到错误但没有看到输出

c++ - 使用 -std=c++11 后未在此范围内声明“stoi”

compiler-errors - 如何使用 std::bind

javascript - 下载文件时在文件内容中获取类型 [object object],而不是使用 angular 7 的 blob

java - 使用 Jackson 解压缩时出现 json 解析器异常