Python: error parsing strings from text file with Ast module
问题 I have a text file (.txt) with the following two strings as so (this is a snippet of a larger file where all strings have the same format): ["('a', '1')", "('b', '2')"] ["('c', '3')", "('d', '4')"] I am using the below code to parse the strings in the text file so that I can access each element for data analysis. The code works for the string if I declare it as a variable, such as: string = ["('c', '3')", "('d', '4')"] But the code does not work for the text file: import ast text_file = open(