Why I'm getting this error when I import pdb? 'module' object has no attribute 'ascii_letters'

允我心安 提交于 2020-06-13 12:21:05

问题


Trying to debug my code, I'm importing the library 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.


回答1:


One of your files is called string.py. Rename it and make sure to delete any *.pyc files from the script's directory.

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'



回答2:


There is 'string.py' file in your folder where all the codes are stored , just rename it and then run the code , it will work fine ;)



来源:https://stackoverflow.com/questions/52841175/why-im-getting-this-error-when-i-import-pdb-module-object-has-no-attribute

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!