imp.load_source() - explanation needed

Discussion in 'Python' started by mynthon, Apr 1, 2009.

  1. mynthon

    mynthon Guest

    Hi!

    I need help. I don't understand what doc says.

    I load module from path testmod/mytest.py using imp.load_source(). My
    code is

    import imp
    testmod = imp.load_source('koko', 'testmod/mytest.py)
    print testmod

    but i don't understand whatt is first (name) argument for. Docs says
    that "The name argument is used to create or access a module object."
    But i still don't understand. I cant do this

    import imp
    testmod = imp.load_source('koko', 'testmod/mytest.py)
    print koko

    How i can access module object using its name? Is " print sys.modules
    ['koko'] " only way or am i missing something?
    mynthon, Apr 1, 2009
    #1
    1. Advertising

  2. On Wed, 2009-04-01 at 12:17 -0700, mynthon wrote:
    > Hi!
    >
    > I need help. I don't understand what doc says.
    >
    > I load module from path testmod/mytest.py using imp.load_source(). My
    > code is
    >
    > import imp
    > testmod = imp.load_source('koko', 'testmod/mytest.py)
    > print testmod
    >
    > but i don't understand whatt is first (name) argument for. Docs says
    > that "The name argument is used to create or access a module object."
    > But i still don't understand. I cant do this
    >
    > import imp
    > testmod = imp.load_source('koko', 'testmod/mytest.py)
    > print koko
    >


    I think that importing and loading are seperate steps. So either

    >>> koko = imp.load_source('koko', 'testmod/mytest.py')


    or

    >>> imp.load_source('koko', 'testmod/mytest.py')
    >>> import koko
    Albert Hopkins, Apr 1, 2009
    #2
    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. Abs
    Replies:
    6
    Views:
    1,853
  2. SMG
    Replies:
    1
    Views:
    1,485
    John Saunders
    Jul 26, 2004
  3. Luis Esteban Valencia
    Replies:
    1
    Views:
    1,370
    Carl Prothman [MVP]
    Jan 12, 2005
  4. Replies:
    0
    Views:
    287
  5. Dave
    Replies:
    2
    Views:
    298
    Nick Coghlan
    Dec 19, 2004
Loading...

Share This Page