newbie question

Steven D'Aprano steve at pearwood.info
Thu Mar 24 07:13:20 EDT 2016


On Thu, 24 Mar 2016 09:39 pm, ast wrote:

> Hi
> 
> I have a string which contains a tupe, eg:
> 
> s = "(1, 2, 3, 4)"
> 
> and I want to recover the tuple in a variable t
> 
> t = (1, 2, 3, 4)
> 
> how would you do ?


py> import ast
py> ast.literal_eval("(1, 2, 3, 4)")
(1, 2, 3, 4)


-- 
Steven




More information about the Python-list mailing list