<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Stephen McInerney wrote:
<blockquote cite="mid:BAY111-W5355B1998C18F4BF4139DDA04E0@phx.gbl"
 type="cite">
  <style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
  </style>&nbsp;<br>
Why does the complex.__str__() method on complex numbers add the
enclosing parentheses?<br>
</blockquote>
<br>
Because it was designed that way and then implemented to follow the
design.<br>
<br>
Or are you asking why it was designed that way? I guess you'd have to
ask the designer.<br>
<br>
At least it is somewhat compatible with str representations of other
data types that contain more than 1 value, e.g. decimal, set, tuple, ...<br>
<br>
<blockquote cite="mid:BAY111-W5355B1998C18F4BF4139DDA04E0@phx.gbl"
 type="cite">It's unwanted</blockquote>
<br>
By some; others like it. I think you mean you don't want it.<br>
<br>
<blockquote cite="mid:BAY111-W5355B1998C18F4BF4139DDA04E0@phx.gbl"
 type="cite">, and it also makes them look like a tuple (other than the
trailing comma).<br>
</blockquote>
<br>
True.<br>
<br>
<blockquote cite="mid:BAY111-W5355B1998C18F4BF4139DDA04E0@phx.gbl"
 type="cite">How can I get rid of it, other than the clunky:<br>
</blockquote>
<br>
Please define "clunky". <br>
<blockquote cite="mid:BAY111-W5355B1998C18F4BF4139DDA04E0@phx.gbl"
 type="cite">&nbsp;<br>
&gt;&gt;&gt; print d<br>
(0.80-0.58j)<br>
&gt;&gt;&gt; print repr(d)[1:-1]<br>
0.80-0.58j<br>
&nbsp;<br>
How can I change complex.__str__() ?<br>
&nbsp; </blockquote>
Create your own subclas<br>
<br>
&gt;&gt;&gt; class C(complex):<br>
... &nbsp;&nbsp;&nbsp; def __str__(self):<br>
... &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return "%s-%sj" % (self.real, self.imag)<br>
... &nbsp;&nbsp;&nbsp; def __init__(self, r, i):<br>
... &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; complex.__init__(self, r, i)<br>
... <br>
&gt;&gt;&gt; c=C(1,2)<br>
&gt;&gt;&gt; c<br>
(1+2j)<br>
&gt;&gt;&gt; print c<br>
'1.0-2.0j';<br>
<br>
This might seem clunky but this is the way to alter behavior of
built-in objects.<br>
<br>
<pre class="moz-signature" cols="72">-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?
</pre>
</body>
</html>