<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'>
Two questions about complex numbers:<BR>
&nbsp;<BR>
a) why are methods __add__,__mul__ defined but not the operators&nbsp;&nbsp;'+','-','*','/'&nbsp;?<BR>
How can I bind the methods to the obvious operators&nbsp;(without creating a custom<BR>
subclass of complex?) It&nbsp;seems&nbsp;pretty weird writing a.__add__(b)<BR>
&nbsp;<BR>
b) Say I have a list ll which mixes real (float) and complex numbers.<BR>
ll = [1, 0.80-0.58j, 0.11+.2j]<BR>
What is the best Python idiom for getting the list of real parts of elements of ll?<BR>
[lx.real for lx in ll] fails&nbsp;because only complex numbers have a 'real'<BR>
attribute, real numbers don't (slightly bizarre).<BR>
Unless I write the not-so-readable:<BR>
[(type(lx) is complex and lx.real or lx) for lx in ll]<BR>
or define my own function.<BR>
&nbsp;<BR>
Do any of you see a need for a math.real() (or math.complex())<BR>
function, which operates on all numeric types?<BR>
Then&nbsp;I could simply take the list comprehension<BR>
[real(lx) for lx in ll]<BR>
Is this worthy of a PEP?<BR>
It seems simple but overlooked.<BR>
&nbsp;<BR>
Regards,<BR>
Stephen<BR><br /><hr />See how Windows connects the people, information, and fun that are part of your life. <a href='http://clk.atdmt.com/MRT/go/msnnkwxp1020093175mrt/direct/01/' target='_new'>See Now</a></body>
</html>