doubt with importing module, given module name

Discussion in 'Python' started by Pradnyesh Sawant, Apr 9, 2007.

  1. Hello,
    I have a string which in reality is the name of a module to be
    imported. The name of the class contained in the module also has the
    same (although with different capitalization). My requirement is to
    import the module, and also create an instance of the class. eg:

    str = "module" #name of module is "module.py"
    cls = str.capitalize() #name of class is "Module"
    inst = cls() #create an instance of class "Module"

    how do i do this?

    Thanks a lot in advance
    Pradnyesh Sawant, Apr 9, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lord0
    Replies:
    1
    Views:
    537
    Thomas Weidenfeller
    Apr 19, 2006
  2. plb
    Replies:
    2
    Views:
    318
  3. chiara
    Replies:
    6
    Views:
    447
    Barry Schwarz
    Oct 6, 2005
  4. 2Barter.net
    Replies:
    0
    Views:
    346
    2Barter.net
    Dec 13, 2006
  5. Bruno Desthuilliers

    Importing module with name given as a variable

    Bruno Desthuilliers, Aug 30, 2008, in forum: Python
    Replies:
    1
    Views:
    184
    Sean Davis
    Aug 30, 2008
Loading...

Share This Page