[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] How do assignments work?



On 5/4/05, Dan <dan@xxxxxxxxxxxxxxxx> wrote:
> In Pygame a Rect has several redundant members that can all be assigned
> to. For example, you can assign to rect.topleft or rect.center, and the
> effect is similar. But assigning to either affects the other, so doesn't
> this require overloading the assignment operator? Python doesn't allow
> that, does it?

You can't overload assignments per se, but you can intercept attribute
access using __getattr__ and __setattr__ (and in newer Python
versions, using properties).

-- 
Sami Hangaslammi