A limitation of Python propertiesA periodically annoying limitation of Python properties on instances is
that you cannot remove or replace a property. (You can implement This restriction exists because properties are actually attributes on
the class, not attributes on the instances. Because of how attribute
lookup works, you can't even sneak a replacement in through the
instance's This means that you can't use properties to implement a highly efficient
'generate once and then cache the answer' instance attribute, where the
first time you access If you need this, the best way is to make a Sidebar: an interesting gotcha in timing attribute accessI did my timing of various attribute access cases using single-letter variable names. To my surprise, there were significant performance differences between the same access method based on what letter I used for the variable name. I suspect that this is because of dictionary hash collisions. I also accidentally discovered that accessing class attributes is slightly faster than accessing instance attributes (and I don't think this one is dependent on variable names). (One comment.)
|
These are my WanderingThoughts GettingAround This is part of CSpace, and is written by ChrisSiebenmann. * * * Atom feeds are available; see the bottom of most pages. Categories: links, linux, programming, python, snark, solaris, spam, sysadmin, tech, unix, web |