1
我用Python 2.7 + PyCharm 2016.2 + Windows 10(64)在我的电脑上遇到了这个奇怪的问题。AttributeError:'模块'对象没有属性'maketrans' - PyCharm
虽然行书:
import urllib
from BeautifulSoup import *
url = raw_input('Enter -')
if (len(url) < 1):
url = "http://python-data.dr-chuck.net/comments_292106.html"
html = urllib.urlopen(url).read()
soup = BeautifulSoup(html)
lst = list()
tags = soup('span')
for tag in tags:
# print 'TAG:', tag
# print 'URL:', tag.get('href', None)
# print 'Contents:', tag.contents
# print 'Attrs:', tag.attrs
num = int(tag.contents[0])
lst.append(num)
print sum(lst)
我已经得到了这样的消息:
C:\Python27\python.exe E:/python/coursera/following_links.py
23
0.8475
Traceback (most recent call
File "E:/python/coursera/following_links.py", line 1, in <module>
import urllib
File "C:\Python27\lib\urllib.py", line 30, in <module>
import base64
File "C:\Python27\lib\base64.py", line 98, in <module>
_urlsafe_encode_translation = string.maketrans(b'+/', b'-_')
AttributeError: 'module' object has no attribute 'maketrans'
Process finished with exit code 1
同样的情况发生在WingIDE。
有趣的是,当使用python的空闲时,这个脚本可以工作。
而且它的工作原理与我的Windows 8(64)(Python 2.7版和PyCharm 2016.2)第二PC
你有PyCharm项目目录中的'string.py'吗? –
Thx寻求帮助。 我确实在项目目录中有我自己的“string.py”。 我是莫朗:( –