Is there any way to access attributes from an imported module?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sun Oct 2 02:55:13 EDT 2011
Andrew Berg wrote:
> I'm not sure the subject's wording is the best, but I'll try to explain.
> I have a main script that imports several modules and I need to be able
> to call methods from a class instance inside that main script from a
> module. Currently, functions can be defined to access the methods, but
> such functions can only be called via commands sent to the main script
> (it's an IRC bot, and commands are sent via IRC). What I want to do is
> call those methods without sending commands (I want to send an IRC
> message from an except clause).
Have I missed something? Why can't you just import the module and call the
methods like you would for any other module and class?
import module
instance = module.Some_Class()
result = instance.method(some, arguments, may, be, needed)
--
Steven
More information about the Python-list
mailing list