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()
添加回答
舉報