redefining a function through assignment

Daniel Britt djbritt at gmail.com
Fri Sep 9 01:56:45 CEST 2005


Hello All,
I am new to Python so if there is an obvious answer to my question please 
forgive me. Lets say I have the following code in mod1.py

class test:
def func1(self):
print 'hello'


Now lets say I have another file called main.py:

import mod1

inst = mod1.test()
inst.func1()


This will print out hello. Now if I added the following to main:
def newFunc(var):
print 'new method'

mod1.test.func1 = newFunc

inst.func1()


This will print out 'new method'. If any other instance of mod1.test is 
created calling func1, func1 will always reference the newFunc function. 
This is less than desirable to say the least. Is there any way of preventing 
this from ever happening? I searched around for quite a while and I haven't 
been able to find anyone who has a solution. The reason I am asking this is 
b/c I want to build an application in python that has plugins. I want to 
make sure that a programmer could not accidently or intentionally clobber 
over another plugins code, which they could easily do. Any help would be 
appreciated. Thanks

~DJ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20050908/c0986005/attachment.html>


More information about the Python-list mailing list