Importing modules from within other modules

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tobiah

    Importing modules from within other modules

    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

  • John Roth

    #2
    Re: Importing modules from within other modules


    "Tobiah" <[email protected] m> wrote in message
    news:821cc9cb8c bc65ad5e9e72584 [email protected] ranews.com...[color=blue]
    > 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?[/color]

    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
    [color=blue]
    >
    > Thanks,
    >
    > Tobiah
    >[/color]


    Comment

    • Tobiah

      #3
      Re: Importing modules from within other modules

      > Python will only import a module once;

      Thanks, this clears things up.

      Tobiah

      Comment

      Working...