use class factory to set required class variables?

Bill Felton subscriptions at cagttraining.com
Thu Jan 27 06:45:25 EST 2011


On Jan 27, 2011, at 4:03 AM, Steven D'Aprano wrote:

> On Wed, 26 Jan 2011 13:37:20 -0800, Alan wrote:
> 
>> I have a class ``A`` that is intentionally incomplete: it has methods
>> that refer to class variables that do not exist. 
> 
> For the record, in Python it is usual to refer to "attributes" rather 
> than "class variables" and "instance variables". In Python, classes are 
> first-class objects (pun not intended) like ints, strings, floats etc., 
> and so a "class variable" would be a variable holding a class, just as a 
> string variable would be a variable holding a string, an int variable 
> holds an int, etc.
> 
Being nit-picky, this is a slightly flawed justification of the terminology. 
In Smalltalk, classes are first class objects (pun similarly not intended).  Yet in Smalltalk we refer to class variables and instance variables.
These are not necessarily variables that 'hold' classes.  In fact, all classes are instances, and so all variables hold instances...
So there's something not quite right about your 'first class objects ... so ... would be a ...'.
This may well be a standard Python convention, and it is certainly not objectionable.  But it isn't well-justified on the basis of the 'first-class-ness' of classes as objects...

Best regards,
Bill




More information about the Python-list mailing list