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


Groups > comp.lang.python > #87450 > unrolled thread

Re: Odd ValueError using float

Started byCameron Simpson <cs@zip.com.au>
First post2015-03-15 09:09 +1100
Last post2015-03-15 09:09 +1100
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.


Contents

  Re: Odd ValueError using float Cameron Simpson <cs@zip.com.au> - 2015-03-15 09:09 +1100

#87450 — Re: Odd ValueError using float

FromCameron Simpson <cs@zip.com.au>
Date2015-03-15 09:09 +1100
SubjectRe: Odd ValueError using float
Message-ID<mailman.377.1426370951.21433.python-list@python.org>
On 14Mar2015 08:28, Emile van Sebille <emile@fenx.com> wrote:
>It ran almost to completion before generating the error again --
>
>(Pdb) decval
>'4'
>(Pdb) type(decval)
><type 'str'>
>(Pdb) len(decval)
>1
>(Pdb) int(decval)
>*** ValueError: invalid literal for int() with base 10: '41.700000000000003'
>
>So there's still something amiss.

Am I missing something obvious here? int() likes only ints, not floats:

    Python 2.7.9 (default, Dec 13 2014, 15:13:49)
    [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> int('1.3')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: invalid literal for int() with base 10: '1.3'

    Python 3.4.3 (default, Feb 27 2015, 00:22:26)
    [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> int('1.3')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: invalid literal for int() with base 10: '1.3'

Cheers,
Cameron Simpson <cs@zip.com.au>

C++ also supports the notion of *friends*: cooperative classes that are
permitted to see each other's private parts.
- Grady Booch, "Object Oriented Design with Applications"

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web