On Sat, Jan 24, 2009 at 20:43, bob gailer <bgai...@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 > thread... > > b = bool(1) > b = bool(0) > > After all, it's not so bad... > > > It really depends on your goals for having this new type. > 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?). 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 <ken...@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 > read this: > 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 > > 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. 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
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor