Re: Using metaclasses to inherit class variables

2006-05-22 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > Fresh copies of class vars so the first one is the correct: ('foo', > 'bar', [], False) Ahh, yeah, then you definitely need the copy.copy call. import copy class ClassVars(type): > ... def __init__(cls, name, bases, dict): > ... for name, valu

Re: Using metaclasses to inherit class variables

2006-05-22 Thread [EMAIL PROTECTED]
Sorry for not being clear. Fresh copies of class vars so the first one is the correct: ('foo', 'bar', [], False) >>> import copy >>> >>> class ClassVars(type): ... def __init__(cls, name, bases, dict): ... for name, value in type(cls).classVars.iteritems(): ... if name not

Re: Using metaclasses to inherit class variables

2006-05-22 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > Oops! This isn't working. As the sequence I'm trying for is def set_classvars(**kwargs): > ... def __metaclass__(name, bases, classdict): > ... for name, value in kwargs.iteritems(): > ... if name not in classdict: > ...

Re: Using metaclasses to inherit class variables

2006-05-22 Thread [EMAIL PROTECTED]
Oops! This isn't working. As the sequence I'm trying for is >>> def set_classvars(**kwargs): ... def __metaclass__(name, bases, classdict): ... for name, value in kwargs.iteritems(): ... if name not in classdict: ... classdict[name] = value ...

Re: Using metaclasses to inherit class variables

2006-05-22 Thread [EMAIL PROTECTED]
Much better. Thanks again. -- http://mail.python.org/mailman/listinfo/python-list

Re: Using metaclasses to inherit class variables

2006-05-22 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > OK no question. I'm only posting b/c it may be something another newbie > will want to google in the future. Now that I've worked thru the > process this turns out to be fairly easy. > > However, if there are better ways please let me know. > > Module = ClassVars.py >

Re: Using metaclasses to inherit class variables

2006-05-22 Thread [EMAIL PROTECTED]
OK no question. I'm only posting b/c it may be something another newbie will want to google in the future. Now that I've worked thru the process this turns out to be fairly easy. However, if there are better ways please let me know. Module = ClassVars.py import copy class ClassVars(type): c

Re: Using metaclasses to inherit class variables

2006-05-21 Thread [EMAIL PROTECTED]
If some one ever wants to build on this in the future, the current form and use is: import copy class ClassVars(type): classVars = dict(fields=[], longest=0) # adjust this def __init__(cls, name, bases, dict): for name, value in ClassVars.classVars.iteritems():

Re: Using metaclasses to inherit class variables

2006-05-20 Thread [EMAIL PROTECTED]
Hmm. setattr() only does a shallow search. Good to know. Your if not name in dict: setattr(cls, name, value) is a more succinct/better way of writing if not cls.__dict__.has_key(var): setattr(cls, var, val) Which i tested a fair bit. OK it appears that both are working for the simple

Re: Using metaclasses to inherit class variables

2006-05-19 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > I want to inherit fresh copies of some class variables. So I set up a > metaclass and meddle with the class variables there. > > Now it would be convenient to run thru a dictionary rather than > explicitly set each variable. However getattr() and setattr() are out > beca