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


Groups > comp.lang.python > #94543

Re: scalar vs array and program control

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'valueerror:': 0.07; 'cc:addr:python-list': 0.09; 'creighton': 0.09; 'literal': 0.09; 'typeerror:': 0.09; 'python': 0.10; 'exception': 0.13; 'do,': 0.15; 'argument': 0.15; 'bytes-like': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'str),': 0.16; 'subject:array': 0.16; 'subject:program': 0.16; 'wrote:': 0.16; 'laura': 0.18; 'string,': 0.18; 'input': 0.18; '>>>': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; '"",': 0.22; 'pass': 0.22; 'sat,': 0.23; 'this:': 0.23; '(most': 0.24; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; 'traceback': 0.33; 'values.': 0.33; 'file': 0.34; 'except': 0.34; 'gives': 0.35; 'received:google.com': 0.35; 'expected': 0.35; 'but': 0.36; 'instead': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'difference': 0.38; 'why': 0.39; 'goes': 0.39; 'you.': 0.64; 'between': 0.65; 'jul': 0.72; 'chrisa': 0.84; 'to:none': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=vRB3xlrxArmgV7KOLyeZfbEZw7Qkbit1Cphuk+IdWw8=; b=iumCqPEZabQh+oKQFDM1U5ZAx4QjJHCkJLt6V8/Mwip0gmC4wegxcJLQM7FOiNsiZ1 btcavBd4x6/hruZGxX/aowsp/2JG2VIo5vidNwe90P8kGmkkkDW3BVMqc3UTL0/LolPl Ji+zQWogaAdznhaecOtHToaL0G0pmH2KmwLhQuThsjwpRFqmPSkODCSIBX+5NuCylaoA DEnBNnNJbE/hVsfl436RhpCq9D5QYxJU/fdWfY6nZM3uq96WV9/8ivV69rX7CV0sF+Li +Z5YTU0+z3uoU/Q23vUFbXGOirN5qnOJxmyx9IqapNH82kjsr5FmMJ4D0C/cA/t51gYX KWRA==
MIME-Version 1.0
X-Received by 10.107.4.1 with SMTP id 1mr28292535ioe.10.1437824052023; Sat, 25 Jul 2015 04:34:12 -0700 (PDT)
In-Reply-To <201507251101.t6PB1LqE021165@fido.openend.se>
References <spluque@gmail.com> <87vbd850qa.fsf@gmail.com> <201507251101.t6PB1LqE021165@fido.openend.se>
Date Sat, 25 Jul 2015 21:34:11 +1000
Subject Re: scalar vs array and program control
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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>
Newsgroups comp.lang.python
Message-ID <mailman.975.1437824061.3674.python-list@python.org> (permalink)
Lines 24
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1437824061 news.xs4all.nl 2852 [2001:888:2000:d::a6]:55636
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:94543

Show key headers only | View raw


On Sat, Jul 25, 2015 at 9:01 PM, Laura Creighton <lac@openend.se> wrote:
> How did I know to look for ValueErrors?
>
>>>> int("1.2")
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   ValueError: invalid literal for int() with base 10: '1.2'
>
> Cause that is what Python gives you.  If it had given you a TypeError
> instead -- which is what I expected it to do, but so it goes -- I
> would have said except TypeError.

The difference between "12", which is valid input for int(), and
"1.2", which isn't, is not the type of the object (both are str), but
their values. That's why the exception is a ValueError. If you pass it
a completely invalid *type*, then you get this:

>>> int([])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: int() argument must be a string, a bytes-like object or a
number, not 'list'

ChrisA

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


Thread

Re: scalar vs array and program control Chris Angelico <rosuav@gmail.com> - 2015-07-25 21:34 +1000

csiph-web