Who am I: can a class instance determine its own name?
Tim Churches
tchur at optushome.com.au
Fri Mar 9 03:14:14 EST 2001
Gregory Jorgensen wrote:
>
> Emile van Sebille's very cool hack aside, I don't understand why you would do
> this. I'm not criticizing; you've got me curious. I've never needed this in
> years and years of programming. I don't think of a variable name as an attribute
> of the object it refers to, because (as one poster pointed out) objects may have
> no name, one name, or several names at any time, and the names referring to an
> object may change during the object's lifetime through assignment, parameter
> passing, etc.
...snip...
Fade to scene of Domestic Bliss...5 year old Wunderkind quietly
supervising the evolution of assorted Pokemon, Better Half reading some
obscure journal, Your Correspondent hacking away on the Faithful Laptop,
frogs croaking in the rain outside. Better Half, who, like Your
Correspondent, is an epidemiologist and not a professional programmer,
asked (out of genuine curiosity, I think) what was so great about
Python. Better half's only exposure to programming languages has been to
SAS (a large, venerable, sprawling, very expensive and very proprietary
business/scientific data management/statistics suite for which the main
3.5GL is an odd but curiously effective mixture of PL/1, Fortran and
BASIC mixed with lots of prepackaged high-level stats and graphics
procedures).
So Clever Clogs (aka Your Correspondent) proceeds to demonstrate some of
the elegance of Python and the advantages of an O-O approach...
from PureGenius import *
# Define a dataset
measles_cases = Dataset("measles_cases")
# Define some variables
sex = Var("sex")
agegroup = Var("agegroup")
# Embed the variables in the dataset
measles_cases.addVar(sex)
measles_cases.addVar(agegroup)
...at which point, stifling a yawn, Better Half asks "Why do you have to
type the variable names twice?". At which point Wunderkind excitedly
announces that Charmeleon has just evolved into Charazard, providing a
convenient excuse for a change of subject and a stern lecture on why
Darwin was right and Lamarck was wrong (Pokemon exhibit Lamarckian
evolution).
But Better Half's question was far from stupid (hello sweetheart if you
are subscribed to this list) and it got me thinking...
You did ask.
Tim C
More information about the Python-list
mailing list