<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Kent Johnson wrote:
<blockquote cite="mid43D75C02.3090801@tds.net" type="cite"><!---->
  <pre wrap="">variable, it has no effect outside the method; inside a method, self is 
just a method parameter, nothing more. There is some magic that gives 
self its value for the call.

When __init__() is called the new instance has already been created, you 
are just initializing its state, not creating the object. You can do 
what you want by defining stime.__new__(). __new__() is responsible for 
actually creating a new object. You still have to check for an stime 
instance in __init__() because __init__() will be called even when 
__new__() returns an existing instance.

Here is a simplified example:

  &gt;&gt;&gt; class stime(object):
  ...   def __new__(cls, value):
  ...     if isinstance(value, cls):
  ...       return value
  ...     return object.__new__(cls, value)
  ...   def __init__(self, value):
  ...     print 'stime.__init__', value
  ...     if isinstance(value, stime):
  ...       return
  ...     self.value = value
  ...
  &gt;&gt;&gt; a=stime(3)
stime.__init__ 3
  &gt;&gt;&gt; a
&lt;__main__.stime object at 0x00A32E90&gt;
  &gt;&gt;&gt; b=stime(a)
stime.__init__ &lt;__main__.stime object at 0x00A32E90&gt;
  &gt;&gt;&gt; b
&lt;__main__.stime object at 0x00A32E90&gt;
  &gt;&gt;&gt; a.value
3
  &gt;&gt;&gt; b.value
3
  &gt;&gt;&gt; a is b
True

Kent
  </pre>
Assigning to self in __init__() just changes the value of the local <br>
</blockquote>
Thanks.&nbsp; I think I've run into this sort of behavior before, but didn't
remember the details well enough to remember the solution (if I've ever
known it).&nbsp; Hopefully this'll be the last of me emails to the Tutor
mailing list on this particular problem. <span class="moz-smiley-s3"><span>
;-) </span></span><br>
<br>
Thanks again,<br>
Orri<br>
<pre class="moz-signature" cols="72">-- 
Email: singingxduck AT gmail DOT com
AIM: singingxduck
Programming Python for the fun of it.</pre>
</body>
</html>