无法导入pprint

8

我是一名新手程序员。每当我尝试在Python IDLE中“import pprint”时,都会出现以下错误:

>>> import pprint
Traceback (most recent call last):
  File "<pyshell#21>", line 1, in <module>
    import pprint
  File "C:\Python34\pprint.py", line 10, in <module>
    pprint(count)
NameError: name 'pprint' is not defined

我想尝试在命令行中使用“pip install pprint”,但这也没有起作用:

PS C:\Python34> pip install pprint
Collecting pprint
Could not find a version that satisfies the requirement pprint (from versions: )
No matching distribution found for pprint 

我认为Python 3.4.3应该自带pprint模块。但是我无法成功导入它,虽然其他模块都能正常工作。我需要pprint模块完成Automate The Boring Stuff with Python书中的一些练习。请问如何让pprint模块工作?感谢您关注我的问题。

1个回答

11

你给一个程序起名叫做pprint。请把这个程序重命名为除pprint.py以外的其他名称,并删除可能存在的任何pprint.pyc文件。


你可以从回溯信息中看出来(导入 pprint 尝试调用 pprint(count),这显然是不应该的) - Adam Smith
为什么Python不建议我们将脚本重命名为其他名称? - Ooker

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接