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


Groups > comp.lang.python > #68431

Re: 'complex' function with string argument.

From Mark H Harris <harrismh777@gmail.com>
Newsgroups comp.lang.python
Subject Re: 'complex' function with string argument.
Date 2014-03-17 11:18 -0500
Organization Aioe.org NNTP Server
Message-ID <lg779d$5f4$2@speranza.aioe.org> (permalink)
References <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com>

Show all headers | View raw


On 3/15/14 11:26 AM, Jayanth Koushik wrote:

This is a very interesting philosophical question, one which I am 
surprised no one has answered; although, I think the reason for that 
might be entirely obvious.

You actually answered your own question, as you were asking it. If the 
doc says "whatever you do, don't push the purple button," well, leave 
the purple button alone.      :)   (I don't know, push it if you want)

If you monitor the PEP process, or have ever taken part in python-ideas, 
or python-dev (either directly, or just lurking) you will notice that 
python is developed through a very interesting active committee process 
(that is really something phenomenal; cool community).

How should one spell a complex number? Should we use i or j ? Should the 
imaginary part be set off somehow?  Should literals be parsed 
differently (or consistently) with correctly formed strings?  Who knows, 
beats me.

consider:
 >>> complex( 3   +  2   j)
SyntaxError: invalid syntax
 >>> complex( 3   +2j  )
(3+2j)
 >>>
I don't know... you tell me.

 >>> complex('3+2j')
(3+2j)
 >>> complex('3 +2j')
Traceback (most recent call last):
   File "<pyshell#17>", line 1, in <module>
     complex('3 +2j')
ValueError: complex() arg is a malformed string
 >>>

Again, beats me.  I just don't know.

But I do know that the spelling book says, Do it this way: 
complex('3+2j').

Seems simple enough.


Philosophically, I tend to think about it this way. A complex number is 
like any other number. I would not form a PI string like this> ' 3 .14 1 
5 9265 3 . . .'   I would rather see it formed like so, '3.1415926535'

This  '3 + 2j'  is not a number, its an algebraic sum.

This  '3+2j'  is a complex number.  Ok, maybe not, but its closer to 
what we expect (I'm sorry, but I like  i  instead  of  j  )

Also, philosophically, C ignores white space;  python does not.

I agree with this now; before I did not. White space is just as much a 
part of how interpretation occurs, within symbol processing/parsing. 
Some choices are arbitrary, some are community concurrence (PEPs), some 
are philosophical, and most are just convenient intuition.

My Greek professor used to say, "there is no 'why' in Greek".

Python is similar.

Cheers

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