Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'string.': 0.05; 'assignment': 0.07; 'error:': 0.07; 'failing': 0.07; 'string': 0.09; 'debugger': 0.09; 'except:': 0.09; 'exception,': 0.09; 'latter': 0.09; 'literal': 0.09; 'meaningful': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'runtime': 0.09; 'subject:using': 0.09; 'try:': 0.09; 'val': 0.09; 'valueerror:': 0.09; 'python': 0.11; '(pdb)': 0.16; 'debugger,': 0.16; 'deletion': 0.16; 'itself,': 0.16; 'nameerror:': 0.16; 'pdb;': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subclass': 0.16; 'throw': 0.16; 'undefined.': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'looked': 0.18; '>>>': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'paul': 0.24; 'post': 0.26; 'defined': 0.27; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'gives': 0.31; 'that.': 0.31; '>>>>': 0.31; 'routine': 0.31; 'terminate': 0.31; 'work:': 0.31; 'writes:': 0.31; 'interface': 0.32; "we're": 0.32; 'says': 0.33; 'checking': 0.33; 'guess': 0.33; 'actual': 0.34; 'trouble': 0.34; 'problem': 0.35; 'something': 0.35; '14,': 0.36; "didn't": 0.36; 'should': 0.36; 'application': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'generating': 0.39; 'help,': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'expression': 0.60; 'conversion': 0.61; 'field.': 0.61; 'making': 0.63; 'name': 0.63; 'more': 0.64; 'contact': 0.67; 'mar': 0.68; 'invalid': 0.68; 'evaluate': 0.72; 'unusual': 0.74; 'completion': 0.78; '10:': 0.84; '2015': 0.84; 'examining': 0.84; 'fail.': 0.84; 'otten': 0.84; 'received:pacbell.net': 0.84; '***': 0.95 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: emile Subject: Re: Odd ValueError using float Date: Sat, 14 Mar 2015 10:08:01 -0700 References: <877fuk71fz.fsf@nightsong.com> 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: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 85 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1426352884 news.xs4all.nl 2900 [2001:888:2000:d::a6]:55530 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:87432 On 03/14/2015 09:08 AM, Peter Otten wrote: > emile wrote: > >> On 03/13/2015 08:09 PM, Chris Angelico wrote: >>> On Sat, Mar 14, 2015 at 1:33 PM, Paul Rubin >>> wrote: >>>> emile writes: >>>>> *** NameError: name 'val' is not defined >>>>> (Pdb) l >>>>> 139 try: >>>>> 140 val = round(float(decval),1) >>>>> 141 except: >>>>> 142 import pdb; pdb.set_trace() >>>> >>>> If 'float' or 'round' throw an exception, the assignment to 'val' never >>>> happens, so 'val' is undefined. Try examining the value of 'decval' in >>>> the debugger to see what is making the conversion fail. >>> >>> That's exactly what the OP did :) Trouble is, it didn't help, because >>> it sure looked as if decval was the string '4'. My best guess was - >>> and is - that it's not just a string. We're looking at an SQL >>> interface routine here, so it may be that there's a string subclass >>> that length-limits itself, on the assumption that it's going into a >>> fixed-length database field. >> >> It ran almost to completion before generating the error again -- >> >> (Pdb) decval >> '4' >> (Pdb) type(decval) >> >> (Pdb) len(decval) >> 1 >> (Pdb) int(decval) >> *** ValueError: invalid literal for int() with base 10: >> '41.700000000000003' >> >> So there's still something amiss. > > Why are you checking > > int(decval) because it sure smells like int should work: (Pdb) "3" > when the actual failing expression is > > round(float(decval),1) > > ? Try to evaluate the latter in the debugger, and if that gives no clue > change > >>>>> 139 try: >>>>> 140 val = round(float(decval),1) >>>>> 141 except: >>>>> 142 import pdb; pdb.set_trace() > > to just > > val = round(float(decval), 1) > > to get a meaningful traceback and post that. I don't get a traceback -- it spews: Fatal Python error: deletion of interned string failed This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. then crashes and I get a Microsoft pop-up that says python.exe has encountered a problem and needs to close. Emile