#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Location
    Pakistan
    Posts
    8
    Rep Power
    0

    dynamic module loading


    Hi everyone
    I m quite new to python.and i m having following problem.
    I read an xml file from my python module
    the names in the file are actually module names that i have to load.
    Each module has a class which is basically extened from Thread class.
    I did see the __import__ example in the python doc(for loading a module),but i m unsure abt How to Instantiate and use the class in that module.

    please any idea?
    TIA
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    griffin,

    It does not matter what the modules do.

    Importing using the __import__ function is very simple, here are three ways to import all achieving the same thing:
    Code:
    #import the time module
    import time
    #import the time module with a different name
    import time as aTime
    #import the time module using a string
    bTime = __import__("time")
    
    print time.time()
    print aTime.time()
    print bTime.time()
    grim
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Location
    Pakistan
    Posts
    8
    Rep Power
    0
    Thanx Grim Archon

IMN logo majestic logo threadwatch logo seochat tools logo