Convert a string to a tuple [duplicate]
问题 This question already has answers here : Parse a tuple from a string? (4 answers) Closed 2 years ago . I read some tuple data from a file. The tuples are in string form, for example Color["RED"] = '(255,0,0)' . How can I convert these strings into actual tuples? I want to use this data in PyGame like this: gameDisplay.fill(Color["RED"]) # but it doesn't have the right data right now: gameDisplay.fill('(255,0,0)') 回答1: You could use the literal_eval of the ast module: ast. literal_eval ( node