【发布时间】:2018-12-20 16:20:55
【问题描述】:
我是 python 新手,我正在尝试为一个检查文本中的诅咒的模块创建一个类。 有人可以帮忙吗?
import urllib
class Checktext:
def __init__(self, text):
self.text = text
def gettext(self):
file = open(self.text, "r")
filetext = open.read()
for word in filetext.split():
openurl = urllib.request.urlopen("http://www.wdylike.appspot.com/?q=" + word)
output = openurl.read()
truer = "true" in str(output)
print(truer)
s = Checktext(r"C:\Users\Tzach\.atom\Test\Training\readme.txt")
Checktext.gettext()
【问题讨论】:
-
您可能想要
s.gettext()而不是Checktext.gettext()。请注意:要包含一段代码,请将其粘贴为文本,然后选择它并按下{}按钮。这会将其缩进 4 个空格,这就是代码块的制作方式。>是 quote 块。
标签: python python-3.x class self