[英]Why I'm getting this error when I import pdb? 'module' object has no attribute 'ascii_letters'
Trying to debug my code, I'm importing the library pdb
尝试调试我的代码,我正在导入库pdb
import sys
from subprocess import check_call
import pdb
/*functions*/
if __name__== "__main__":
/* Code */
I'm receiving this error:我收到此错误:
File "reg.py", line 11, in <module>
import pdb
File "/usr/lib/python2.7/pdb.py", line 9, in <module>
import cmd
File "/usr/lib/python2.7/cmd.py", line 53, in <module>
IDENTCHARS = string.ascii_letters + string.digits + '_'
AttributeError: 'module' object has no attribute 'ascii_letters'
If I create a new python file and I try to run pdb, the same error occur.如果我创建一个新的 python 文件并尝试运行 pdb,则会发生同样的错误。
One of your files is called string.py
.您的文件之一称为string.py
。 Rename it and make sure to delete any *.pyc
files from the script's directory.重命名它并确保从脚本目录中删除所有*.pyc
文件。
It is a very bad practice to use names of built-in modules for your own files for that very reason.出于这个原因,为您自己的文件使用内置模块的名称是一种非常糟糕的做法。
$ echo "import pdb" > string.py
$ python string.py
File "string.py", line 1, in <module>
import pdb
File "D:\Python37\lib\pdb.py", line 73, in <module>
import cmd
File "D:\Python37\lib\cmd.py", line 50, in <module>
IDENTCHARS = string.ascii_letters + string.digits + '_'
AttributeError: module 'string' has no attribute 'ascii_letters'
您的文件夹中有一个“string.py”文件,其中存储了所有代码,只需重命名它然后运行代码,它就可以正常工作;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.