Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'attribute': 0.07; 'indeed,': 0.07; 'python': 0.08; 'argument,': 0.09; 'failing': 0.09; 'received:mail-lpp01m010-f46.google.com': 0.09; 'subject:error': 0.09; '16,': 0.15; "'int'": 0.16; 'skip:) 10': 0.16; 'subject:result': 0.16; '\xa0print': 0.16; 'cc:addr:python- list': 0.16; 'wrote:': 0.18; 'simpler': 0.18; 'thanks,': 0.19; '(which': 0.19; '(most': 0.21; 'header:In-Reply-To:1': 0.22; 'feb': 0.22; 'traceback': 0.24; 'convert': 0.25; 'cc:2**0': 0.26; 'subject:" ': 0.28; 'skip:" 30': 0.28; 'message- id:@mail.gmail.com': 0.29; 'fine.': 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'subject:format': 0.30; 'error': 0.30; 'version': 0.32; 'received:209.85.215.46': 0.32; 'thu,': 0.32; 'object': 0.33; 'daniel': 0.34; 'last):': 0.34; 'two': 0.36; 'but': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; 'think': 0.38; 'should': 0.38; 'skip:\xa0 10': 0.39; 'received:209.85.215': 0.39; 'received:209': 0.39; 'results': 0.64; '26,': 0.73; 'subject:its': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=6AcKimo8RrdAv731VJZwRTNGoUFpaRYj9BoP7EP6U0M=; b=goEJ9lij/iufflg9Jg9Fw0/JvHsRwO44g39IVYpO0MHvkvXsAf2WEVH2hSr8scInrY KUg1LZ0dZPz/62M0zSdOkYUfBzU6bIF9hVFZz0r06i2JOdVbC8Qpt8Mm7bl29CzyPtC4 FV+HLSuZH9Y9fCJOnrTAuc9oRl4RZZeZiAU6U= MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Thu, 16 Feb 2012 17:29:27 -0700 Subject: Re: format a measurement result and its error in "scientific" way To: Daniel Fetchinson Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Python X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1329438598 news.xs4all.nl 6912 [2001:888:2000:d::a6]:55934 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:20529 On Thu, Feb 16, 2012 at 3:21 PM, Daniel Fetchinson wrote: > Thanks, it's simpler indeed, but gives me an error for value=3D1.267, err= or=3D0.08: > > Traceback (most recent call last): > =A0File "/home/fetchinson/bin/format_error", line 26, in > =A0 =A0print format_error( sys.argv[1], sys.argv[2] ) > =A0File "/home/fetchinson/bin/format_error", line 9, in format_error > =A0 =A0error_scale +=3D error.scaleb( -error_scale ).to_integral( =A0).ad= justed( =A0) > =A0File "/usr/lib64/python2.6/decimal.py", line 3398, in scaleb > =A0 =A0ans =3D self._check_nans(other, context) > =A0File "/usr/lib64/python2.6/decimal.py", line 699, in _check_nans > =A0 =A0other_is_nan =3D other._isnan() > AttributeError: 'int' object has no attribute '_isnan' > > Which version of python are you using? 2.7.1. At a guess, it's failing because scaleb() (which was new in 2.6) is buggily expecting a decimal argument, but adjusted() returns an int= . Convert the results of the two adjusted() calls to decimals, and I think it should be fine.