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.
Are you looking for the __import__ function?
精彩评论