tags:

views:

34

answers:

1

I've created an IRC bot in Python from scratch just for the fun of it. I've got a way to load modules into it, but you have to manually type out the code to load each module as below:

if data.find('PRIVMSG %s :add_mod foo\r\n' % channel)
    enabled_mods.append(foo)
if data.find('PRIVMSG %s :rm_mod foo\r\n' % channel)
    enabled_mods.remove(foo)
if data.find('PRIVMSG %s :add_mod bar\r\n' % channel)
    enabled_mods.append(bar)
if data.find('PRIVMSG %s :rm_mod bar\r\n' % channel)
    enabled_mods.remove(bar)
for mod in enabled_mods:
    mod(data,irc,channel,nick)

Is there any way to load each module using a for loop for example? Any other suggestions? Such as:

modules = [foo,bar]
for module in modules:
    if data.find('PRIVMSG %s :add_mod %s\r\n' % (channel,module))
        enabled_mods.append(module)
    if data.find('PRIVMSG %s :rm_mod %s\r\n' % (channel,module))
        enabled_mods.remove(module)

SOLVED.

A: 

Are you looking for the __import__ function?

S.Lott
no, aha. I've made a bot that allows extra modules to be added in via type "add_mod [module_name]" into the irc client.
zorvee