complex() bug or feature?
Michael Hudson
mwh at python.net
Thu Nov 8 07:12:48 EST 2001
Carsten Gaebler <clpy at snakefarm.org> writes:
> Hi there,
>
> is this the way complex() is supposed to work?
I doubt it.
> Python 2.2b1 (#2, Oct 22 2001, 10:47:30)
> [GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> complex('1', '1')
> (1+0j)
> >>>
>
> If complex() allows stings as arguments (like float()), what's
> happened to the imaginary part?
According to the docs, this is in error:
,--http://python.sourceforge.net/devel-docs/lib/built-in-funcs.html---
| complex(real[, imag])
| Create a complex number with the value real + imag*j or convert a
| string or number to a complex number. Each argument may be any
| numeric type (including complex). If imag is omitted, it defaults
| to zero and the function serves as a numeric conversion function
| like int(), long() and float(); in this case it also accepts a
| string argument which should be a valid complex number.
`---------------------------------------------------------------------
I read that to mean that if the first arg is a string, it should be
the only arg. The code simply ignores imag if real is a string. Do
you want to open a bug, or shall I?
Cheers,
M.
--
> Look I don't know. Thankyou everyone for arguing me round in
> circles.
No need for thanks, ma'am; that's what we're here for.
-- LNR & Michael M Mason, cam.misc
More information about the Python-list
mailing list