Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #87648
| Path | csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.016 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'literal': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:using': 0.09; 'val': 0.09; 'valueerror:': 0.09; 'python': 0.11; 'int(s)': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wrote:': 0.18; 'thanks.': 0.20; 'import': 0.22; 'header:User-Agent:1': 0.23; 'bytes': 0.24; 'issue,': 0.24; 'skip:" 20': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'thus': 0.29; 'code': 0.31; '"",': 0.31; '>>>>': 0.31; 'ctypes': 0.31; 'file': 0.32; 'probably': 0.32; 'skip:c 30': 0.32; '(most': 0.33; 'actual': 0.34; 'but': 0.35; 'skip:4 10': 0.37; 'to:addr:python- list': 0.38; 'issue': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'more': 0.64; 'mar': 0.68; 'invalid': 0.68; '10:': 0.84; '2014,': 0.84; 'object:': 0.84; 'otten': 0.84; 'received:pacbell.net': 0.84; 'discovering': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | emile <emile@fenx.com> |
| Subject | Re: Odd ValueError using float |
| Date | Tue, 17 Mar 2015 13:48:35 -0700 |
| References | <mailman.336.1426284641.21433.python-list@python.org> <877fuk71fz.fsf@nightsong.com> <CAPTjJmoxL0ux3mHAd8UCZmdbTHe_Yz5i9Y8XrzJ7NAuy8WZ4sA@mail.gmail.com> <me1k2i$ljt$1@ger.gmane.org> <me1mdb$nri$1@ger.gmane.org> <me1ptc$gna$1@ger.gmane.org> <me1ucs$n98$1@ger.gmane.org> <me2439$cvf$1@ger.gmane.org> <me43c8$i7r$1@ger.gmane.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | adsl-69-226-129-65.dsl.pltn13.pacbell.net |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 |
| In-Reply-To | <me43c8$i7r$1@ger.gmane.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.19 |
| 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.501.1426625323.21433.python-list@python.org> (permalink) |
| Lines | 40 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1426625323 news.xs4all.nl 2866 [2001:888:2000:d::a6]:50679 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:87648 |
Show key headers only | View raw
On 03/15/2015 07:01 AM, Peter Otten wrote:
> Probably not helpful, but I can provoke the behaviour you see by toggling
> bytes with ctypes, thus simulating a corrupted str object:
>
> Python 2.7.6 (default, Mar 22 2014, 22:59:56)
> [GCC 4.8.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import ctypes
>>>> s = "41.700000000000003"
>>>> ctypes.c_ubyte.from_address(id(s) + 16).value = 1
>>>> s
> '4'
>>>> len(s)
> 1
>>>> float(s)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ValueError: invalid literal for float(): 41.700000000000003
>>>> int(s)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ValueError: invalid literal for int() with base 10: '41.700000000000003'
I dug through the code and ctypes was in the mix. Without discovering
the actual issue, I did manage to work around the issue by replacing:
val = round(float(decval),1)
with
val = round(float("".join([ii if ii=="." else str(int(ii)) for ii in
decval])),1)
Thanks.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Odd ValueError using float emile <emile@fenx.com> - 2015-03-13 15:10 -0700
Re: Odd ValueError using float Paul Rubin <no.email@nospam.invalid> - 2015-03-13 19:33 -0700
Re: Odd ValueError using float Chris Angelico <rosuav@gmail.com> - 2015-03-14 14:09 +1100
Re: Odd ValueError using float emile <emile@fenx.com> - 2015-03-14 08:28 -0700
Re: Odd ValueError using float Chris Angelico <rosuav@gmail.com> - 2015-03-15 02:52 +1100
Re: Odd ValueError using float Peter Otten <__peter__@web.de> - 2015-03-14 17:08 +0100
Re: Odd ValueError using float emile <emile@fenx.com> - 2015-03-14 10:08 -0700
Re: Odd ValueError using float emile <emile@fenx.com> - 2015-03-14 10:17 -0700
Re: Odd ValueError using float Peter Otten <__peter__@web.de> - 2015-03-14 19:24 +0100
Re: Odd ValueError using float emile <emile@fenx.com> - 2015-03-14 13:01 -0700
Re: Odd ValueError using float Peter Otten <__peter__@web.de> - 2015-03-15 15:01 +0100
Re: Odd ValueError using float emile <emile@fenx.com> - 2015-03-17 13:48 -0700
csiph-web