问题
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