File Paramaterized Abstract Factory

Fredrik Lundh fredrik at pythonware.com
Wed Jan 11 02:37:28 EST 2006


Charles Krug wrote:

> What I'd like is to do something like this:
>
> factoryFile = sys.argv[1] # we assume that argv[1] implements a
>                           # correct ThingMaker interface.

sys.argv[1] is a string, so I assume that you meant to say that
the module named by argv[1] implements the correct interface.

> Anywho, my problem is with the whole Miracle thing.
>
> I've tried using __import__:
>
> a = 'HerFactory'
> __import(a)
>
> Which returns:
>
> <module 'HerFactory' from 'HerFactory.py'>

try:

    factoryObject = __import__(factoryFile)
    print dir(factoryObject)

this should give you a list of the functions in the given module,
or an ImportError if it doesn't exist.

> But after that I can't access the members.

what did you try, and what happened ?  if at all possible, cut and
paste the code you tried (your examples above contained obvious
typos), and the actual error messages, so we don't have to guess.

</F>






More information about the Python-list mailing list