0
我一直在玩更換名單
下面是我的代碼:
與上面的代碼def extract_info(msg):
created_time = msg['created_time'].replace('T', ' ').replace('+0000', '')
mess = msg.get('message', 'Key "message" is not present.').replace('\n', '').replace(',', '').encode('utf8')
message = (mess[:498] + '..') if len(mess) > 498 else mess
user_id = msg['from']['id']
return (created_time, message, user_id)
def main():
ts = FacebookSearch()
data = ts.search('dishwasher')
js = json.loads(data)
messages = (extract_info(msg) for msg in js.get('data', []))
write_csv('fb_dishwasher.csv', messages, append=True)
問題:
我想操縱「信息」通過使用通過替換忽略列表。
有點兒什麼我想做的事:
ignore = ["you","all","has","can","that", "the", "what", "with", "and", "to", "this", "would","from", "your", "which", "while", "these", "when", "way", "like", "been", "will", "look"]
def replaceall(s, olds, replacement):
for old in olds:
s = s.replace(old, replacement)
return s
最大的問題是我不知道如何在上面忽略列表融入我現有的上面「extract_info」功能。我是否創建一個新的函數,或者是否在現有函數中創建嵌套函數? (這感覺不對)。我真的很想有一些想法和想法來達到這個目的。
你似乎已經具備替代功能,這可以在extract_info函數中被調用。什麼是問題?也許這個問題我不清楚。 –
你想如何「通過使用忽略列表操縱消息」?信息應該如何改變?如果這些話被刪除?請舉一個例子。 –
應忽略忽略列表中的單詞。例如:「去商店」將是「去商店」 – user2748540