Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #106861

Re: Most probably a stupid question, but I still want to ask

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Stephen Hansen <me+python@ixokai.io>
Newsgroups comp.lang.python
Subject Re: Most probably a stupid question, but I still want to ask
Date Sun, 10 Apr 2016 22:42:23 -0700
Lines 37
Message-ID <mailman.23.1460353347.15650.python-list@python.org> (permalink)
References <neelcl$mer$1@gioia.aioe.org> <570b02db$0$1605$c3e8da3$5496439d@news.astraweb.com> <nef3a3$15nk$2@gioia.aioe.org> <570b2000$0$22142$c3e8da3$5496439d@news.astraweb.com> <nef7lq$1ati$1@gioia.aioe.org> <1460350018.3507765.574780001.5531F1C0@webmail.messagingengine.com> <mailman.18.1460350021.15650.python-list@python.org> <45c1ee67-16c5-45b3-bf3c-f33efb42d3c3@googlegroups.com> <1460353343.3517647.574804705.5CF46A82@webmail.messagingengine.com>
Mime-Version 1.0
Content-Type text/plain
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de c4aiqrflCWJQSVxk3HY1WAdToB8g6bzAroHUGC6dmmWw==
Return-Path <me+python@ixokai.io>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'exception.': 0.07; 'puts': 0.07; 'so?': 0.07; 'valueerror:': 0.07; 'subject:question': 0.08; 'ast': 0.09; 'received:internal': 0.09; 'reliably': 0.09; 'subject:still': 0.09; 'throws': 0.09; 'valueerror': 0.09; '(either': 0.16; '--s': 0.16; '2016': 0.16; '63,': 0.16; 'malformed': 0.16; 'message-id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:66.111.4.27': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:out3-smtp.messagingengine.com': 0.16; 'received:psf.io': 0.16; 'worst': 0.16; 'wrote:': 0.16; 'string': 0.17; 'input': 0.18; '>>>': 0.20; 'fix': 0.21; '"",': 0.22; 'stephen': 0.22; 'wrote': 0.23; 'import': 0.24; '(most': 0.24; 'header:In-Reply- To:1': 0.24; 'skip:" 20': 0.26; 'skip:_ 20': 0.26; 'error': 0.27; 'raise': 0.29; 'reporting': 0.29; 'traceback': 0.33; 'file': 0.34; 'could': 0.35; "isn't": 0.35; 'but': 0.36; 'monday,': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'skip:v 20': 0.38; 'skip:z 10': 0.38; 'received:66': 0.38; 'log': 0.38; 'someone': 0.38; 'why': 0.39; 'data': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'avoid': 0.61; 'header:Message-Id:1': 0.61; 'skip:n 10': 0.62; 'more': 0.63; 'safe': 0.63; 'utc+5:30,': 0.84; 'maybe,': 0.91; 'subject:want': 0.93
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d=ixokai.io; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=UFts6byMRqXNu8IBIHfHXpcFbQI=; b=WyNY7n nSshkK+GRW9XYmD/ruLp04wLeDA/y/K9HMfDxTNESePJ4coXClkA3Bt384pzIrXz vj5QncA+K5Ai5JJrBvoltEE1fLTocFa5S9LXRLDJ9yZyL5+3KAJcpwyAhV/k4rGa zv5x9crs+u2aqcuEm+cFabMCmYrE3ajdPizX4=
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=UFts6byMRqXNu8I BIHfHXpcFbQI=; b=Hz2NjKapytlfGTgRCghNI8ts8i6AylQLScg5O+77aZyh9qy CgAYnMNaGrl0KASShraNtnq2ruvQKz1uQgK5Lu0clbxPd5Gp881WIzRrjz+VZjUa t90VA5/PVUc92oYxScxyAUxK8BU5Y7yVzr8Hh6UAtFJSA/piFVP2NiW3nZe4=
X-Sasl-Enc dbo11lzApafCPbAE8rmUIQDLcfwj/Wzmwf06VeRt7mkT 1460353343
X-Mailer MessagingEngine.com Webmail Interface - ajax-82e6ff7b
In-Reply-To <45c1ee67-16c5-45b3-bf3c-f33efb42d3c3@googlegroups.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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <1460353343.3517647.574804705.5CF46A82@webmail.messagingengine.com>
X-Mailman-Original-References <neelcl$mer$1@gioia.aioe.org> <570b02db$0$1605$c3e8da3$5496439d@news.astraweb.com> <nef3a3$15nk$2@gioia.aioe.org> <570b2000$0$22142$c3e8da3$5496439d@news.astraweb.com> <nef7lq$1ati$1@gioia.aioe.org> <1460350018.3507765.574780001.5531F1C0@webmail.messagingengine.com> <mailman.18.1460350021.15650.python-list@python.org> <45c1ee67-16c5-45b3-bf3c-f33efb42d3c3@googlegroups.com>
Xref csiph.com comp.lang.python:106861

Show key headers only | View raw


On Sun, Apr 10, 2016, at 10:18 PM, Rustom Mody wrote:
> On Monday, April 11, 2016 at 10:17:13 AM UTC+5:30, Stephen Hansen wrote:
> > On Sun, Apr 10, 2016, at 09:03 PM, Fillmore wrote:
> > > and the (almost always to be avoided) use of eval()
> > 
> > FWIW, there's ast.literal_eval which is safe and there's no reason to
> > avoid it.
> 
> Its error reporting is clunky:
> 
> >>> from ast import literal_eval as le
> >>> le("(1)")
> 1
> >>> le("(1,)")
> (1,)
> >>> le("1")
> 1
> >>> le("{1:x}")
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/usr/lib/python2.7/ast.py", line 80, in literal_eval
>     return _convert(node_or_string)
>   File "/usr/lib/python2.7/ast.py", line 63, in _convert
>     in zip(node.keys, node.values))
>   File "/usr/lib/python2.7/ast.py", line 62, in <genexpr>
>     return dict((_convert(k), _convert(v)) for k, v
>   File "/usr/lib/python2.7/ast.py", line 79, in _convert
>     raise ValueError('malformed string')
> ValueError: malformed string

So? Worst case scenario, someone puts invalid data into the file and it
throws an exception. Could it be more specific? Maybe, but I don't see
why it needs to be. If your input isn't reliably formatted, catch
ValueError and log it and fix (either what wrote it or change how you
read it).

--S

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Most probably a stupid question, but I still want to ask Fillmore <fillmore_remove@hotmail.com> - 2016-04-10 18:51 -0400
  Re: Most probably a stupid question, but I still want to ask Chris Angelico <rosuav@gmail.com> - 2016-04-11 08:58 +1000
  Re: Most probably a stupid question, but I still want to ask Ben Finney <ben+python@benfinney.id.au> - 2016-04-11 09:04 +1000
  Re: Most probably a stupid question, but I still want to ask Stephen Hansen <me+python@ixokai.io> - 2016-04-10 16:30 -0700
    Re: Most probably a stupid question, but I still want to ask Fillmore <fillmore_remove@hotmail.com> - 2016-04-10 20:17 -0400
      Re: Most probably a stupid question, but I still want to ask Stephen Hansen <me+python@ixokai.io> - 2016-04-10 17:32 -0700
      Re: Most probably a stupid question, but I still want to ask Terry Reedy <tjreedy@udel.edu> - 2016-04-10 21:45 -0400
        Re: Most probably a stupid question, but I still want to ask Marko Rauhamaa <marko@pacujo.net> - 2016-04-11 08:41 +0300
  one-element tuples [Was: Most probably a stupid question, but I still want to ask] Fillmore <fillmore_remove@hotmail.com> - 2016-04-10 20:13 -0400
    Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] Stephen Hansen <me+python@ixokai.io> - 2016-04-10 17:19 -0700
    Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] Stephen Hansen <me+python@ixokai.io> - 2016-04-10 17:18 -0700
    Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] Chris Angelico <rosuav@gmail.com> - 2016-04-11 10:20 +1000
    Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] Fillmore <fillmore_remove@hotmail.com> - 2016-04-10 20:22 -0400
      Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] Stephen Hansen <me+python@ixokai.io> - 2016-04-10 17:28 -0700
      Re: one-element tuples Ben Finney <ben+python@benfinney.id.au> - 2016-04-11 10:31 +1000
        Re: one-element tuples Fillmore <fillmore_remove@hotmail.com> - 2016-04-10 20:48 -0400
          Re: one-element tuples Ben Finney <ben+python@benfinney.id.au> - 2016-04-11 10:56 +1000
            Re: one-element tuples Grant Edwards <invalid@invalid.invalid> - 2016-04-11 14:10 +0000
              Re: one-element tuples Fillmore <fillmore_remove@hotmail.com> - 2016-04-11 10:11 -0400
                Re: one-element tuples Grant Edwards <invalid@invalid.invalid> - 2016-04-11 14:26 +0000
          Re: one-element tuples Ned Batchelder <ned@nedbatchelder.com> - 2016-04-10 18:00 -0700
          Re: one-element tuples Stephen Hansen <me+python@ixokai.io> - 2016-04-10 18:07 -0700
          Re: one-element tuples "Martin A. Brown" <martin@linux-ip.net> - 2016-04-10 18:08 -0700
            Re: one-element tuples Fillmore <fillmore_remove@hotmail.com> - 2016-04-10 23:19 -0400
              Re: one-element tuples Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-11 09:57 +0300
              Re: one-element tuples Larry Hudson <orgnut@yahoo.com> - 2016-04-11 23:01 -0700
          Re: one-element tuples Ben Finney <ben+python@benfinney.id.au> - 2016-04-11 11:36 +1000
            Re: one-element tuples Fillmore <fillmore_remove@hotmail.com> - 2016-04-10 22:57 -0400
              Re: one-element tuples Ben Finney <ben+python@benfinney.id.au> - 2016-04-11 14:10 +1000
                Re: one-element tuples Fillmore <fillmore_remove@hotmail.com> - 2016-04-11 00:43 -0400
                Re: one-element tuples Stephen Hansen <me+python@ixokai.io> - 2016-04-10 21:54 -0700
                Re: one-element tuples Ben Finney <ben+python@benfinney.id.au> - 2016-04-11 15:40 +1000
                Re: one-element tuples Rustom Mody <rustompmody@gmail.com> - 2016-04-10 22:07 -0700
          Re: one-element tuples BartC <bc@freeuk.com> - 2016-04-11 12:15 +0100
            Re: one-element tuples Marko Rauhamaa <marko@pacujo.net> - 2016-04-11 15:12 +0300
              Re: one-element tuples Grant Edwards <invalid@invalid.invalid> - 2016-04-11 14:12 +0000
    Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] Ben Finney <ben+python@benfinney.id.au> - 2016-04-11 10:30 +1000
    Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] MRAB <python@mrabarnett.plus.com> - 2016-04-11 01:33 +0100
      Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] Dan Sommers <dan@tombstonezero.net> - 2016-04-11 02:22 +0000
        Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] Chris Angelico <rosuav@gmail.com> - 2016-04-11 12:34 +1000
    Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] Chris Angelico <rosuav@gmail.com> - 2016-04-11 10:38 +1000
    Parens do create a tuple (was: one-element tuples [Was: Most probably a stupid question, but I still want to ask]) Ben Finney <ben+python@benfinney.id.au> - 2016-04-11 10:45 +1000
    Re: Parens do create a tuple (was: one-element tuples [Was: Most probably a stupid question, but I still want to ask]) Chris Angelico <rosuav@gmail.com> - 2016-04-11 10:50 +1000
    Re: Parens do create a tuple Ben Finney <ben+python@benfinney.id.au> - 2016-04-11 10:57 +1000
    Re: Parens do create a tuple Chris Angelico <rosuav@gmail.com> - 2016-04-11 11:04 +1000
    Re: Parens do create a tuple (was: one-element tuples [Was: Most probably a stupid question, but I still want to ask]) Stephen Hansen <me@ixokai.io> - 2016-04-10 18:03 -0700
    Re: Parens do create a tuple (was: one-element tuples [Was: Most probably a stupid question, but I still want to ask]) Tim Chase <python.list@tim.thechases.com> - 2016-04-10 19:52 -0500
    Re: Parens do create a tuple Ben Finney <ben+python@benfinney.id.au> - 2016-04-11 11:41 +1000
      Re: Parens do create a tuple Steven D'Aprano <steve@pearwood.info> - 2016-04-11 12:32 +1000
        Re: Parens do create a tuple Random832 <random832@fastmail.com> - 2016-04-10 22:51 -0400
          Re: Parens do create a tuple Steven D'Aprano <steve@pearwood.info> - 2016-04-11 14:08 +1000
            Re: Parens do create a tuple Random832 <random832@fastmail.com> - 2016-04-11 01:27 -0400
              Re: Parens do create a tuple Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-04-11 18:01 +1000
                Re: Parens do create a tuple Random832 <random832@fastmail.com> - 2016-04-11 09:42 -0400
        Re: Parens do create a tuple Chris Angelico <rosuav@gmail.com> - 2016-04-11 13:02 +1000
        Re: Parens do create a tuple Ben Finney <ben+python@benfinney.id.au> - 2016-04-11 14:08 +1000
    Re: Parens do create a tuple Chris Angelico <rosuav@gmail.com> - 2016-04-11 11:51 +1000
      Re: Parens do create a tuple Steven D'Aprano <steve@pearwood.info> - 2016-04-11 12:57 +1000
    Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] Tim Chase <python.list@tim.thechases.com> - 2016-04-10 19:46 -0500
  Re: Most probably a stupid question, but I still want to ask Steven D'Aprano <steve@pearwood.info> - 2016-04-11 11:50 +1000
    Re: Most probably a stupid question, but I still want to ask Fillmore <fillmore_remove@hotmail.com> - 2016-04-10 22:48 -0400
      Re: Most probably a stupid question, but I still want to ask Steven D'Aprano <steve@pearwood.info> - 2016-04-11 13:54 +1000
        Re: Most probably a stupid question, but I still want to ask Fillmore <fillmore_remove@hotmail.com> - 2016-04-11 00:03 -0400
          Re: Most probably a stupid question, but I still want to ask Stephen Hansen <me+python@ixokai.io> - 2016-04-10 21:46 -0700
            Re: Most probably a stupid question, but I still want to ask Rustom Mody <rustompmody@gmail.com> - 2016-04-10 22:18 -0700
              Re: Most probably a stupid question, but I still want to ask Stephen Hansen <me+python@ixokai.io> - 2016-04-10 22:42 -0700
                Re: Most probably a stupid question, but I still want to ask Rustom Mody <rustompmody@gmail.com> - 2016-04-10 23:57 -0700
          Re: Most probably a stupid question, but I still want to ask Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-04-11 17:50 +1000

csiph-web