Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Tim Chase Newsgroups: comp.lang.python Subject: Re: newbie question Date: Thu, 24 Mar 2016 05:58:36 -0500 Lines: 23 Message-ID: References: <56f3c3eb$0$4546$426a74cc@news.free.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de HCkiXyqNbu4xUGQ6Q0CvYAOXCwo3RmBLroT6ty16tkqQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:question': 0.08; 'cc:addr:python-list': 0.09; '(1,': 0.09; 'ast': 0.09; 'tuple': 0.09; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'instead:': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'variable': 0.18; 'cc:addr:python.org': 0.20; 'cc:2**1': 0.22; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'subject:: ': 0.37; 'received:10': 0.37; 'charset:us-ascii': 0.37; 'safety': 0.66; 'received:23': 0.84; 'recover': 0.91 X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-MC-Relay: Neutral X-MailChannels-SenderId: wwwh|x-authuser|tim@thechases.com X-MailChannels-Auth-Id: wwwh X-MC-Loop-Signature: 1458817310751:1604879693 X-MC-Ingress-Time: 1458817310750 In-Reply-To: X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) X-AuthUser: tim@thechases.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105600 On 2016-03-24 11:49, David Palao wrote: >> 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 ? > > Use "eval": > s = "(1, 2, 3, 4)" > t = eval(s) Using eval() has security implications. Use ast.literal_eval for safety instead: import ast s = "(1, 2, 3, 4)" t = ast.literal_eval(s) -tkc