Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #87450
| Date | 2015-03-15 09:09 +1100 |
|---|---|
| From | Cameron Simpson <cs@zip.com.au> |
| Subject | Re: Odd ValueError using float |
| References | <me1k2i$ljt$1@ger.gmane.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.377.1426370951.21433.python-list@python.org> (permalink) |
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"
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Odd ValueError using float Cameron Simpson <cs@zip.com.au> - 2015-03-15 09:09 +1100
csiph-web