Importing modules from within other modules

Discussion in 'Python' started by Tobiah, Sep 14, 2003.

  1. Tobiah

    Tobiah Guest

    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
     
    Tobiah, Sep 14, 2003
    #1
    1. Advertising

  2. Tobiah

    John Roth Guest

    "Tobiah" <> wrote in message
    news:...
    > 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
    >
     
    John Roth, Sep 14, 2003
    #2
    1. Advertising

  3. Tobiah

    Tobiah Guest

    > Python will only import a module once;

    Thanks, this clears things up.

    Tobiah
     
    Tobiah, Sep 14, 2003
    #3
    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. Eric

    importing other .py files

    Eric, Feb 14, 2004, in forum: Python
    Replies:
    1
    Views:
    283
    Jarek Zgoda
    Feb 14, 2004
  2. plb
    Replies:
    2
    Views:
    372
  3. Martin P. Hellwig
    Replies:
    0
    Views:
    301
    Martin P. Hellwig
    Apr 6, 2008
  4. Peter Peyman Puk

    Importing v reloading modules modules

    Peter Peyman Puk, Mar 19, 2010, in forum: Python
    Replies:
    0
    Views:
    318
    Peter Peyman Puk
    Mar 19, 2010
  5. Tim Olsen

    modules including other modules

    Tim Olsen, May 29, 2007, in forum: Ruby
    Replies:
    4
    Views:
    148
    Adriano Mitre
    Jan 20, 2011
Loading...

Share This Page