imp.load_source() - explanation needed

M

mynthon

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?
 
A

Albert Hopkins

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

or
 

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

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top