Importing modules from within other modules

T

Tobiah

Hi,

If I write a module for general purpose use
that needs say, 'sys', 'os', 're' etc...
and I import those modules from within my module,
does this cause inefficiency when an existing program
that already imports these modules, imports mine,
or is there a safeguard similar to #ifdef MODULE_NAME
used in the C preprossessor?

Thanks,

Tobiah
 
J

John Roth

Tobiah said:
Hi,

If I write a module for general purpose use
that needs say, 'sys', 'os', 're' etc...
and I import those modules from within my module,
does this cause inefficiency when an existing program
that already imports these modules, imports mine,
or is there a safeguard similar to #ifdef MODULE_NAME
used in the C preprossessor?

Python will only import a module once; if you ask for it
again, you'll get the reference that Python stores in an
internal table.

It's possible to get an incompletely loaded module if you
have two modules that import each other. That's a very
messy situation called a circular import, but you actually
have to do it to get into trouble.

John Roth
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top