Dynamical loading of modules

Discussion in 'Python' started by Jacob Kroon, Oct 3, 2005.

  1. Jacob Kroon

    Jacob Kroon Guest

    Hi, I'm having some problems with implementing dynamical module loading.
    First let me
    describe the scenario with an example:


    apple.py defines a class 'Apple', banana defines a class 'Banana'. The
    problem lies in the
    fact that I want to be able to just drop a new .py-file, for instance
    peach.py, and not change
    __init__.py, and it should automatically pickup the new file in
    __init__.py. I've come halfway
    by using some imp module magic in __init__.py, but the problem I have is
    that the instantiated
    objects class-names becomes fruit.apple.Apple/fruit.banana.Banana, whild
    I want it to be

    Is there a smarter way of accomplishing what I am trying to do ?
    If someone could give me a small example of how to achieve this I would
    be very grateful.

    Regards Jacob Kroon
    Jacob Kroon, Oct 3, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.