简体   繁体   English

为什么在导入 pdb 时会出现此错误? “模块”对象没有属性“ascii_letters”

[英]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.

相关问题 VS 代码中的 Pandas:AttributeError:模块“字符串”没有属性“ascii_letters” - Pandas in VS Code: AttributeError: module 'string' has no attribute 'ascii_letters' 为什么我得到 object has no attribute error in python tkinter - Why I'm getting object has no attribute error in python tkinter 为什么我在添加“as”时得到模块没有属性错误 - Why Am I getting Module has no attribute error when adding "as" 我得到了AttributeError:当我在Windows上运行我的程序时,&#39;module&#39;对象没有属性&#39;fork&#39;。 我怎样才能解决这个问题? - I'm getting AttributeError: 'module' object has no attribute 'fork' when i run my program on windows. How can i fix this? 谁能告诉我为什么我收到错误 [AttributeError: 'list' object has no attribute 'encode'] - Can anyone tell my why I'm getting the error [AttributeError: 'list' object has no attribute 'encode'] 为什么在使用csv模块时仍然出现错误“ AttributeError:&#39;_ io.TextIOWrapper&#39;对象没有属性&#39;writerows”? - Why do I keep getting the error “AttributeError: '_io.TextIOWrapper' object has no attribute 'writerows” when using csv module? 为什么我不断收到AttributeError:“模块”对象没有属性 - Why do I keep getting AttributeError: 'module' object has no attribute 我不断收到错误的“模块”对象没有属性“初始化” - i keep getting the error 'module' object has no attribute 'init' 使用 ascii_letters 用下一个替换字母时出错 - Error in replacing alphabets with the next one using ascii_letters 为什么我收到此错误(AttributeError:&#39;module&#39;对象没有属性&#39;openssl_md_meth_names&#39;)? - Why I am getting this error(AttributeError: 'module' object has no attribute 'openssl_md_meth_names')?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM