[Edu-sig] Those polyhedra again (ch.py)
kirby urner
kirby.urner at gmail.com
Thu Apr 15 04:54:11 CEST 2010
On Wed, Apr 14, 2010 at 4:58 PM, kirby urner <kirby.urner at gmail.com> wrote:
> """
> This version adds an instance variable self.keep
> that propagates though the scaling method to
> the next of kin. For example:
>
"propagates through"... phraseology maybe not that clear.
The "keep" word is like from "castle keep", with a polyhedron
being like a special box for a keepsake. The scaling method
instantiates a new object of type M with volume and edges
re-scaled according to the argument. I don't bother with surface
area. The name 'keep' is pointing back to the same object at
the origin of this chain of progeny.
I find this an interesting study in Python's naming conventions,
-- plus the polyhedra are designed to be instructive...
Interactive session with remarks...
Instantiate an object with keep bound to a
dictionary object
>>> rh = ch.R_Dodeca(keep={'mites':48})
double the size through two "generations" of
subsequent object:
>>> rh1 = rh * 2
>>> rh2 = rh1 * 2
>>> rh2.volume
384
Note that rh2.keep still points to the same
object as the original rh.keep does.
>>> rh2.keep
{'mites': 48}
adding a new (key,value) pair to rh.keep does
not rebind it to a new object -- rh.keep still shares
the same referent as rh2.keep
>>> rh.keep['a']=96
>>> rh2.keep
{'a': 96, 'mites': 48}
Here, in rebinding rh.keep to an immutable string, we
no longer name the same object as rh1.keep or rh2.keep
rh.keep is not a "class variable".
>>> rh.keep = 'new value'
>>> rh2.keep
{'a': 96, 'mites': 48}
Kirby
More information about the Edu-sig
mailing list