refactoring so that multiple changes can be made with one variable?

John Salerno johnjsal at NOSPAMgmail.com
Tue Nov 14 22:52:43 CET 2006


Paddy wrote:

> You could keep a handle on all object instances created then go through
> the objects making appropriate changes, e.g:
> 
> 
> class Character(object):
>      instances = []
>      def __init__(self, name, strength, dexterity, intelligence):
>           instances.append(self)
>           # as before ...
>      def mod_instances(self):
>           for inst in instances:
>                inst.some_property += 1     # or whatever
> # (Untested)

But doesn't this require that the change be predetermined so you can 
code it into the method?

I don't necessarily need a programmatic way to do this, just a simple 
way to go back to the code and edit a single thing, instead of having to 
update all the numbers.



More information about the Python-list mailing list