<br><br><div class="gmail_quote">On Sat, Jan 24, 2009 at 20:43, bob gailer <span dir="ltr"><<a href="mailto:bgailer@gmail.com">bgailer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div bgcolor="#ffffff" text="#000000"><div><div></div><div class="Wj3C7c">
Vicent wrote:<blockquote type="cite"><div class="gmail_quote"><div><br>
It would be great if "b.value = 0" could be just written as "b = 0"
without changing type as a result.<br>
</div>
</div>
</blockquote>
<br></div></div>
Assignment in effect does a del b, then creates a new b based on the
expression. There is no way in Python right now to do that. The closest
I can come is to support the syntax b(0) and b(1) to emulate
assignment. That would require that I add to the Bit class:<br>
<br>
def __call__(self, value):<br>
self.value = value<div class="Ih2E3d"></div></div></blockquote><div><br>OK, I think I understand...<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div bgcolor="#ffffff" text="#000000"><div class="Ih2E3d"><br>
<blockquote type="cite">
<div class="gmail_quote">
<div><br>
What happens if every time I want to update the value of "b", I use "b=
Bit(0)" , "b=Bit(1)", and so on?? Is like "building" the object each
time? It is less efficient, isn't it?<br>
</div>
</div>
</blockquote>
<br></div>
Yes and yes.<div class="Ih2E3d"></div></div></blockquote><div><br>Ok...<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div bgcolor="#ffffff" text="#000000">
<div class="Ih2E3d"><br>
<blockquote type="cite">
<div class="gmail_quote">
<div><br>
You are going to kill me</div>
</div>
</blockquote>
<br></div>
Are you saying that to prepare your self for a negative response from
me, or in hopes that I would not have such? I view everything we do
here as incremental improvement. I am glad you are thinking of
alternatives.</div></blockquote><div><br>Thank you...<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div bgcolor="#ffffff" text="#000000">
<div class="Ih2E3d"><br>
<br>
<blockquote type="cite">
<div class="gmail_quote">
<div>, but... Maybe the solution is not to re-define what already
exists —boolean data type, but just using it, as suggested at the
beginning of the thread...<br>
<br>
b = bool(1)<br>
b = bool(0)<br>
<br>
After all, it's not so bad...<br>
</div>
</div>
</blockquote>
<br></div>
It really depends on your goals for having this new type. <br><div class="Ih2E3d">
</div></div></blockquote><div><br><br>I was thinking about this during this night (sometimes, it is near to sleep or when having a shower when new ideas come out!, isn't it?).<br><br>Maybe, all I need to do is this:<br>
<br>>>> bit = bool<br><br>And then, I can do this:<br><br>>>> b = bit(0) <br></div></div><br>I mean, just using "bit" as an "alias" for "bool" [, and forget about any new class or whatever]. In fact, type for "b" is "bool":<br>
<br>>>> type(b)<br><type 'bool'><br clear="all"><br><br><br><div class="gmail_quote">On Sat, Jan 24, 2009 at 22:46, Kent Johnson <span dir="ltr"><<a href="mailto:kent37@tds.net">kent37@tds.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="Ih2E3d"><br>
<br>
</div>You have an incorrect idea about how variables and assignment work in<br>
Python. Type is associated with a value, not a name. You might want to<br>
read this:<br>
<a href="http://personalpages.tds.net/%7Ekent37/kk/00012.html" target="_blank">http://personalpages.tds.net/~kent37/kk/00012.html</a><br>
<br>
and this classic:<br>
<a href="http://effbot.org/zone/python-objects.htm" target="_blank">http://effbot.org/zone/python-objects.htm</a><br>
<font color="#888888"><br>
</font></blockquote></div><br><br>Yes, I was a bit confused, although I've already read those links you provide (I think you gave them to me in another recent post). They are very good explanations.<br><br>I think I hadn't get that "0" is always integer, but now I get it. If I want to make it boolean (bit-like), it should be referred as "bool(0)". [It is like that, isn't it????]<br>
<br>-- <br>Vicent<br>