Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #68456

Re: 'complex' function with string argument.

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
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; 'python.': 0.02; 'syntax': 0.04; 'run-time': 0.05; "subject:' ": 0.07; 'function:': 0.09; 'subject:string': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'ah!': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'literals': 0.16; 'literals,': 0.16; 'literals.': 0.16; 'matters,': 0.16; 'notation': 0.16; 'notations': 0.16; "skip:' 60": 0.16; 'sorts': 0.16; 'such,': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'convenient': 0.24; 'integer': 0.24; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; '(unless': 0.31; 'though.': 0.31; 'subject:with': 0.35; "can't": 0.35; 'definition': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'seconds': 0.37; 'skip:- 10': 0.38; 'does': 0.39; 'even': 0.60; 'negative': 0.60; 'skip:a 30': 0.61; 'numbers': 0.61; 'you.': 0.62; 'between': 0.67; 'mar': 0.68; '5:15': 0.84; 'bare': 0.84; 'proves': 0.84; 'absolutely': 0.87; 'to:none': 0.92; 'outcome': 0.93
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=r0cgfml7aMM/0ahFfPUZez/Px2TSBTebttyExJ13s3E=; b=KniTlMzgqZYFtDfm+8nFxhD8mGeuLanWwzzBBMgCMvmOFrgS6ZpLN59O6LeO2uGLWG +SEBhxaKfvFIGp58DF9cpDBSvD+a+Bepft/gozyPNRM2YS2tre+0ZLDkGB/vqIcuv+wQ LTj0tu4rbGhSAEAonPv1U3MSRYiRUAbKIgwMW12TFHRMy/84WCWhF4PHUS6i/m54w79n oN3yWnRtZu8PYRB9KzXr9MuU3F3b353WSb7CflgGt2zTyXPf6hOAh3m2+HWLJlX71szQ JVhlNfnHD3LJ2viNnrIsbp2pdtywVbIiAjGMFeZ1x3i2dGBG3j+X/1bFEaQzgz7wXi9j cYbA==
MIME-Version 1.0
X-Received by 10.66.102.39 with SMTP id fl7mr27007299pab.43.1395084738337; Mon, 17 Mar 2014 12:32:18 -0700 (PDT)
In-Reply-To <87siqgr5p1.fsf@elektro.pacujo.net>
References <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> <lg779d$5f4$2@speranza.aioe.org> <mailman.8201.1395075805.18130.python-list@python.org> <87y508r8ro.fsf@elektro.pacujo.net> <mailman.8218.1395082794.18130.python-list@python.org> <87siqgr5p1.fsf@elektro.pacujo.net>
Date Tue, 18 Mar 2014 06:32:18 +1100
Subject Re: 'complex' function with string argument.
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <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 <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.8219.1395084747.18130.python-list@python.org> (permalink)
Lines 45
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1395084747 news.xs4all.nl 2874 [2001:888:2000:d::a6]:53377
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:68456

Show key headers only | View raw


On Tue, Mar 18, 2014 at 6:22 AM, Marko Rauhamaa <marko@pacujo.net> wrote:
> Chris Angelico <rosuav@gmail.com>:
>
>> On Tue, Mar 18, 2014 at 5:15 AM, Marko Rauhamaa <marko@pacujo.net> wrote:
>>> Is "-2.0" a literal?
>>>
>>> What's the outcome of
>>>
>>>    -2.0.__str__()
>>
>> If you mean (-2.0).__str__(), then it returns '-2.0', but that proves
>> nothing.
>
> The point is, you don't need to "philosophize" about complex literals
> when even negative numbers don't have literals in Python.

Ah! I get you.

The difference between literals and constants is one that almost never
matters, though. Python may not have a syntax for negative or complex
literals, but it does have notations for various sorts of constants,
which function the same way. (Literals are by definition constants.)
So Python may not have a convenient notation for "number of seconds in
a week" (unless you work with DNS and find the bare integer 604800
convenient), but you can write 7*24*60*60 and it's just as good in a
function:

>>> ast.dump(ast.parse("7*24*60*60"))
'Module(body=[Expr(value=BinOp(left=BinOp(left=BinOp(left=Num(n=7),
op=Mult(), right=Num(n=24)), op=Mult(), right=Num(n=60)), op=Mult(),
right=Num(n=60)))])'
>>> def f(x):
    return x + 7*24*60*60

>>> dis.dis(f)
  2           0 LOAD_FAST                0 (x)
              3 LOAD_CONST               6 (604800)
              6 BINARY_ADD
              7 RETURN_VALUE

There's absolutely no run-time cost to writing it out, and you get to
be flexible with whitespace and such, which you can't do with
literals.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

'complex' function with string argument. Jayanth Koushik <jnkoushik@gmail.com> - 2014-03-15 09:26 -0700
  Re: 'complex' function with string argument. Mark H Harris <harrismh777@gmail.com> - 2014-03-17 11:18 -0500
    Re: 'complex' function with string argument. Chris Angelico <rosuav@gmail.com> - 2014-03-18 04:03 +1100
      Re: 'complex' function with string argument. Marko Rauhamaa <marko@pacujo.net> - 2014-03-17 20:15 +0200
        Re: 'complex' function with string argument. Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-17 12:28 -0600
        Re: 'complex' function with string argument. Chris Angelico <rosuav@gmail.com> - 2014-03-18 05:59 +1100
          Re: 'complex' function with string argument. Marko Rauhamaa <marko@pacujo.net> - 2014-03-17 21:22 +0200
            Re: 'complex' function with string argument. Chris Angelico <rosuav@gmail.com> - 2014-03-18 06:32 +1100
            Re: 'complex' function with string argument. Steven D'Aprano <steve@pearwood.info> - 2014-03-18 04:08 +0000
      Re: 'complex' function with string argument. Mark H Harris <harrismh777@gmail.com> - 2014-03-17 13:20 -0500
    Re: 'complex' function with string argument. Steven D'Aprano <steve@pearwood.info> - 2014-03-18 04:52 +0000
      Re: 'complex' function with string argument. Chris Angelico <rosuav@gmail.com> - 2014-03-18 15:59 +1100
      Re: 'complex' function with string argument. Mark H Harris <harrismh777@gmail.com> - 2014-03-18 11:14 -0500
        Re: 'complex' function with string argument. wxjmfauth@gmail.com - 2014-03-19 00:30 -0700
          Re: 'complex' function with string argument. Marko Rauhamaa <marko@pacujo.net> - 2014-03-19 10:51 +0200
            Re: 'complex' function with string argument. wxjmfauth@gmail.com - 2014-03-19 02:52 -0700
              Re: 'complex' function with string argument. Marko Rauhamaa <marko@pacujo.net> - 2014-03-19 12:09 +0200
                Re: 'complex' function with string argument. Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-19 04:33 -0600
                Re: 'complex' function with string argument. Marko Rauhamaa <marko@pacujo.net> - 2014-03-19 12:53 +0200
                Re: 'complex' function with string argument. Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-19 13:35 -0600
                Re: 'complex' function with string argument. Skip Montanaro <skip@pobox.com> - 2014-03-19 06:04 -0500
                Re: 'complex' function with string argument. wxjmfauth@gmail.com - 2014-03-19 07:35 -0700
                Re: 'complex' function with string argument. Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-19 12:45 -0600
  Re: 'complex' function with string argument. Mark Dickinson <mdickinson@enthought.com> - 2014-03-17 17:55 +0000
  Re: 'complex' function with string argument. Terry Reedy <tjreedy@udel.edu> - 2014-03-17 18:06 -0400
  Re: 'complex' function with string argument. Skip Montanaro <skip@pobox.com> - 2014-03-17 18:59 -0500
  Re: 'complex' function with string argument. Chris Angelico <rosuav@gmail.com> - 2014-03-18 11:16 +1100
  Re: 'complex' function with string argument. Skip Montanaro <skip@pobox.com> - 2014-03-17 20:07 -0500
  Re: 'complex' function with string argument. Christian Gollwitzer <auriocus@gmx.de> - 2014-03-18 08:04 +0100
    Re: 'complex' function with string argument. Chris Angelico <rosuav@gmail.com> - 2014-03-18 18:11 +1100
    Re: 'complex' function with string argument. Steven D'Aprano <steve@pearwood.info> - 2014-03-18 08:00 +0000
      Re: 'complex' function with string argument. Christian Gollwitzer <auriocus@gmx.de> - 2014-03-18 09:21 +0100
        Re: 'complex' function with string argument. Marko Rauhamaa <marko@pacujo.net> - 2014-03-18 16:00 +0200

csiph-web