Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Importing modules from within other modules

Reply
Thread Tools

Importing modules from within other modules

 
 
Tobiah
Guest
Posts: n/a
 
      09-14-2003
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

 
Reply With Quote
 
 
 
 
John Roth
Guest
Posts: n/a
 
      09-14-2003

"Tobiah" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) s.com...
> 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

>
> Thanks,
>
> Tobiah
>



 
Reply With Quote
 
 
 
 
Tobiah
Guest
Posts: n/a
 
      09-14-2003
> Python will only import a module once;

Thanks, this clears things up.

Tobiah

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
modules including other modules Tim Olsen Ruby 4 01-20-2011 09:30 AM
Importing v reloading modules modules Peter Peyman Puk Python 0 03-19-2010 05:09 PM
sys.path and importing modules from other directories Martin P. Hellwig Python 0 04-06-2008 02:04 AM
How to keep a module with the same name as a module it is importing from importing itself? plb Python 2 02-08-2005 03:14 PM



Advertisments