1 回答

TA贡献2021条经验 获得超8个赞
我相信我们可以让你的班级工作。您的代码现在确实正在运行,但是由于您似乎只对 的返回值感兴趣,因此可能必须单独调用:certain_words()
class News:
def __init__(self, rss_dict, t1, t2, filename):
# init elided, but just these two functions called
self.print_headlines_test()
self.write_and_read()
def print_headlines_test(self):
# processing elided, except:
self.allheadlines = allheadlines
def write_and_read(self):
# processing elided, except the next line (Note no return)
self.df = df
def certain_words(self):
# processing elided, except for this return
return self.df[result & result2]
# client code is now two lines:
c = News(my_dict_of_rss, target1, target2, 'filename.csv')
words = c.certain_words()
# If you don't care about keeping the instance 'c' around, then you can do it in one line:
words = News(my_dict_of_rss, target1, target2, 'filename.csv').certain_words()
添加回答
举报