Question about properties.

Steve Holden steve at holdenweb.com
Fri Aug 10 08:17:43 EDT 2007


king kikapu wrote:
> On Aug 10, 1:33 pm, Marc 'BlackJack' Rintsch <bj_... at gmx.net> wrote:
>> On Fri, 10 Aug 2007 03:21:29 -0700, king kikapu wrote:
>>> Hi,
>>> i read in a book the following code snippet that is dealing with
>>> properties:
>>> class ProtectAndHideX(object):
>>>     def __init__(self, x):
>>>         assert isinstance(x, int), '"x" must be an integer!"'
>>>         self.__x = ~x
>>>     def get_x(self):
>>>         return ~self.__x
>>>     x = property(get_x)
>>> Can anyone please help me understand what the symbol "~" does here ??
>> This has nothing to do with properties.  For integer objects ``~`` is the
>> bitwise negation or invertion operator.
>>
>> Ciao,
>>         Marc 'BlackJack' Rintsch
> 
> Xmmm...ok then but what is actually doing there ?? I removed it and
> things seems to work the same way...
> 
Observe the name of the class. I believe the integer value is inverted 
merely as a demonstration that the value can be "obscured" somehow - in 
a more complex example the author might have insisted in string values, 
the encrypted them. It's not essential to the example, it merely shows 
that the value retrieved from the property can be computed from 
underlying attributes.

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd           http://www.holdenweb.com
Skype: holdenweb      http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------




More information about the Python-list mailing list