Using eval, or something like it...
Joe Strout
joe at strout.net
Fri Nov 21 11:05:59 EST 2008
On Nov 21, 2008, at 8:58 AM, r0g wrote:
> I hadn't really appreciated the consequences of this till now though
> e.g. that an instance might do a = a + 1 without affecting it's
> siblings
> but that b.append("fish") would affect b for everyone. I don't know
> if I
> will find any uses for that kind of behaviour but it doesn't hurt to
> understand it :-)
Yes, it's critical to understanding any OOP language.
> Isn't Python's behaviour a little peculiar in this respect though,
> compared to classes in other languages?
No, it's exactly the same.
> i.e. Are instances in other OO
> languages like Smalltalk, C++ fully independent copies or do their
> attribute names just point to one common object until reassigned
> like in
> python? (Or have I still not it at all?!)
You're still a little confused, perhaps. But I think this will clear
it up:
<http://www.strout.net/info/coding/valref/>
I wrote this to help people in exactly your situation, so please do
give me feedback and let me know how it did or didn't help.
Thanks,
- Joe
More information about the Python-list
mailing list