From: Terry Reedy on 21 Jun 2010 14:06 On 6/21/2010 11:24 AM, Stephen Hansen wrote: > On 6/21/10 8:08 AM, Stephen Hansen wrote: >> If you don't want a class to have attributes added at runtime, the > The Pythonic way to achieve that is to... simply NOT add attributes at > runtime. > > I.e., choose to follow the rule you've decided on. Or add a __setattr__ method, but the above is easier. -- Terry Jan Reedy
From: Stephen Hansen on 21 Jun 2010 14:55 On 6/21/10 11:06 AM, Terry Reedy wrote: > On 6/21/2010 11:24 AM, Stephen Hansen wrote: >> On 6/21/10 8:08 AM, Stephen Hansen wrote: >>> If you don't want a class to have attributes added at runtime, the > >> The Pythonic way to achieve that is to... simply NOT add attributes at >> runtime. >> >> I.e., choose to follow the rule you've decided on. > > Or add a __setattr__ method, but the above is easier. I'd sort of argue that adding a __setattr__ for that purpose is un-Pythonic (as opposed to using __setattr__ for some functional purpose and that restriction being a side-effect). Its possible to do it, sure; but its also possible to use __slots__ to do so as well. But its bad form in both cases. But, that argument is largely Nit meeting Pick and having a fight about which kettle is blacker. :) -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/
First
|
Prev
|
Pages: 1 2 Prev: Decode II (more complex) Next: What module to parse/generate ical files? |