AttributeError:“module”对象没有属性“maketrans”PyCharm

2024-04-23 11:42:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我在我的电脑上遇到了一个奇怪的问题:Python2.7+PyCharm 2016.2+Windows10(64)。在

运行脚本时:

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)

我得到这样的信息:

^{pr2}$

同样的情况也发生在Wingede。在

有趣的是,当使用python的Idle时,这个脚本可以工作。在

它也可以在我的第二台装有Windows 8(64)的电脑上运行(Python 2.7和PyCharm 2016.2)


Tags: import脚本urlhtmltagcontentstagsurllib
1条回答
网友
1楼 · 发布于 2024-04-23 11:42:25

我认为这是在幕后发生的。为了执行您的命令,Python必须做一些工作,它无法找到它需要的文件。这也许可以解释为什么它可以在空闲和PC上工作,但在Wing IDE这样的其他计算机上却不行。在

相关问题 更多 >