# [Tutor] Defining "bit" type

Vicent vginer at gmail.com
Sun Jan 25 11:13:52 CET 2009

```On Sat, Jan 24, 2009 at 20:43, bob gailer <bgailer at gmail.com> wrote:

>  Vicent wrote:
>
>
> It would be great if   "b.value = 0"   could be just written as "b = 0"
> without changing type as a result.
>
>
> 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:
>
>   def __call__(self, value):
>     self.value = value
>

OK, I think I understand...

>
>
> 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?
>
>
> Yes and yes.
>

Ok...

>
>
> You are going to kill me
>
>
> 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.
>

Thank you...

>
>
>  , 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
>
> b = bool(1)
> b = bool(0)
>
> After all, it's not so bad...
>
>
> It really depends on your goals for having this new type.
>

or when having a shower when new ideas come out!, isn't it?).

Maybe, all I need to do is this:

>>> bit = bool

And then, I can do this:

>>> b = bit(0)

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":

>>> type(b)
<type 'bool'>

On Sat, Jan 24, 2009 at 22:46, Kent Johnson <kent37 at tds.net> wrote:

>
>
> You have an incorrect idea about how variables and assignment work in
> Python. Type is associated with a value, not a name. You might want to
> http://personalpages.tds.net/~kent37/kk/00012.html<http://personalpages.tds.net/%7Ekent37/kk/00012.html>
>
> and this classic:
> http://effbot.org/zone/python-objects.htm
>
>

provide (I think you gave them to me in another recent post). They are very
good explanations.

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????]

--
Vicent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090125/f2eab5d6/attachment.htm>
```