Defining class methods outside of classes

L

Lord Landon

Hi, I'm working on a bot written in python. It will consist of a
mostly empty class that will then call a loader which in turn defines
functions and adds them to the class. At the moment, I do this by
using execfile(file,globals()) and calling a load(bot) method defined
in every "module" which takes the functions defined in that perticular
module and does bot.function=function. The problem with that is when I
call bot.function() self doesn't get passed as an argument to the
function. Is there anything I can do to sort this besides calling
bot.function(bot, ...) everytime?
 
P

Peter Otten

Lord said:
Hi, I'm working on a bot written in python. It will consist of a
mostly empty class that will then call a loader which in turn defines
functions and adds them to the class. At the moment, I do this by
using execfile(file,globals()) and calling a load(bot) method defined
in every "module" which takes the functions defined in that perticular
module and does bot.function=function. The problem with that is when I
call bot.function() self doesn't get passed as an argument to the
function. Is there anything I can do to sort this besides calling
bot.function(bot, ...) everytime?

Either add the method to the class or make it an instance method.
.... def __init__(self):
.... self.name = "bot"
....hello from bot

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top