Path: csiph.com!usenet.pasdenom.info!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'syntax': 0.04; 'literal': 0.09; 'subject:module': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; "wouldn't": 0.14; "'d',": 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'literal,': 0.16; 'literals': 0.16; 'literals.': 0.16; 'magic': 0.16; 'mode,': 0.16; 'notation,': 0.16; 'sessions,': 0.16; 'sorts': 0.16; 'tag,': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'all,': 0.19; 'feb': 0.22; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'string,': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'source': 0.25; 'script': 0.25; 'this:': 0.26; 'header:In-Reply- To:1': 0.27; 'mode': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'too.': 0.31; 'decimal': 0.31; 'quotes': 0.31; 'time:': 0.31; 'another': 0.32; 'running': 0.33; 'fri,': 0.33; 'maybe': 0.34; 'could': 0.34; "can't": 0.35; 'something': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'so,': 0.37; 'pm,': 0.38; 'how': 0.40; 'different': 0.65; 'within': 0.65; 'between': 0.67; 'anything.': 0.68; 'confusion.': 0.84; 'object:': 0.84; 'bless': 0.91; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=hBz8sr2ONuhX0dlDSERDmkX2GRC0P98dDygrUZV1KCw=; b=0lJyKhQcZBQ50SQIqDSsQ/1qnguOeuWNRjWsCb54HtrylNChUwoR4Fml9JL2XpfO2m 06I15dJtw+1fHugUSiwvrB7y9iTcyr47T7BUTKD476sRqEpQ6giCu9KEwhlc0apVPjwX K+tYf732dGo3XyY6/SvGwDXTKE55gM++EWGManbiHJ1OORj5rGwdwPP9tuzxFYYfkB1d OfbN2ky5zAcGj1I1odgC10YT7ZhTEEoXe8DHVqIuhZmnMu97JJsRevbHrN83Y0bU7CsH qYykGBXCk/7RSkdMt84rX5ZNdNL9BGBBBb4svRsE1PT7RAHTUzu0dhtcJLN44XqR/DVs YP3A== MIME-Version: 1.0 X-Received: by 10.66.11.66 with SMTP id o2mr1145737pab.142.1393563610268; Thu, 27 Feb 2014 21:00:10 -0800 (PST) In-Reply-To: References: <02cdd9c7-aef7-4cc7-a813-cd1c9627ceb4@googlegroups.com> <94b1962a-0004-4c5b-b484-972a166b88b5@googlegroups.com> <55525f2c-fd3a-4927-b642-2dbf5eae7e9b@googlegroups.com> <360e87d2-4daf-4222-8ebe-51f3e4d1fade@googlegroups.com> <9f7b535f-9e5d-45df-96f6-6cd8f6b4a524@googlegroups.com> <530fff58$0$11113$c3e8da3@news.astraweb.com> Date: Fri, 28 Feb 2014 16:00:10 +1100 Subject: Re: extend methods of decimal module From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393563614 news.xs4all.nl 2964 [2001:888:2000:d::a6]:60330 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:67195 On Fri, Feb 28, 2014 at 3:41 PM, Mark H. Harris wrote: > So, I am thinking I need to mods... maybe an idmath.py for interactive sessions, and then dmath.py for for running within my scientific scripts... ?? No; the solution is to put quotes around your literals in interactive mode, too. There's no difference between interactive and script mode, and adding magic to interactive mode will only cause confusion. Alternatively, there is another solution that's been posited from time to time: Decimal literals. We currently have three forms of numeric literal, which create three different types of object: >>> type(1) >>> type(.1) >>> type(1j) If we had some other tag, like 'd', we could actually construct a Decimal straight from the source code. Since source code is a string, it'll be constructed from that string, and it'll never go via float. Something like this: >>> type(0.1d) which currently is a SyntaxError, so it wouldn't collide with anything. The question is how far Python wants to bless the Decimal type with syntax - after all, if Decimal can get a literal notation, why can't Fraction, and why can't all sorts of other types? And that's a huge can of worms. ChrisA