Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #94543 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2015-07-25 21:34 +1000 |
| Last post | 2015-07-25 21:34 +1000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: scalar vs array and program control Chris Angelico <rosuav@gmail.com> - 2015-07-25 21:34 +1000
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-07-25 21:34 +1000 |
| Subject | Re: scalar vs array and program control |
| Message-ID | <mailman.975.1437824061.3674.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web