Ethan Furman wrote:
Alan Harris-Reid wrote:
The code is not usually in class.__init__ (otherwise I would have
used the self. prefix), but I like your self.__dict__.update(...)
solution and I'll try and remember it.
The code I was thinking of goes something like as follows (don't have
a specific example to hand, but the principal is the same)...
NewClass = BaseClass()
NewClass.attr1 = value1
NewClass.attr2 = value2
NewClass.attr3 = value3
etc.
So if there are more than a couple of attributes to set for a class
instance, how would you approach it (short of passing the values as
parameters to BaseClass)?
Unless I'm missing something (your use-case, perhaps? ;) in this
example NewClass is *not* a class -- it's an instance of BaseClass,
and you are dynamically adding attributes to it.
It's definitely a switch coming from FoxPro (me, too!), but it is well
worth it once your brain starts working pythonically.
~Ethan~
Hi Ethan,
You are correct - NewClass is an instance of BaseClass and I chose a
very bad class-name as an example.
Good to see ex-Fox people on this list. I have recently got stuck-into
learning Python after my last VFP contract finished last December - wish
I had started years ago. Really glad I went for Python, which I thought
would be the easiest transition from Foxpro (I looked at other
languages, but none came near to Python in terms of popularity and
developer-friendly syntax). What's your story?
Regards,
Alan
--
http://mail.python.org/mailman/listinfo/python-list