Save list in a file

南楼画角 提交于 2019-12-04 07:17:41

问题


I have to write a script that will read a file tempo_rogue_guide_utf8, find several words in its text and save them in a new file (one form by line). I was told to use JSON but I can't seem to make it work.

The expected output should be saved in the new file like this: you can remove you want to do you can activate you can keep

Also, I keep having the message unexpected character after line continuation character after the ...IGNORECASE) in the code below:

def main():
    try:
        my_file = open('tempo_rogue_guide_utf8', encoding='utf-8')
        data = my_file.read()
        print("File opened correctly")
        my_file.close()

    except IOError:
        print("Could not open file")
        return

    forms=re.findall((you\s+)(want\s+to\s+|have\s+to\s+|need\s+to\s+|should\s+|must\s+|can\s+|could\s+)(\w+)), data, re.IGNORECASE)

    json.dump(forms, new_file_tp_utf8) 

来源:https://stackoverflow.com/questions/58937917/save-list-in-a-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!