limit module import to only certain symbols?

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

    limit module import to only certain symbols?

    Say I have the following module named "mymodule"

    import string
    var1 = 'a'
    var2 = 'b'

    And I want to import its symbols into another script:

    from mymodule import *

    This will import 3 symbols (string, var1, var2)

    Is it possible to limit it so that import * will only import specified
    items? So that:

    from mymodule import *

    Would import only var1 and var2?

    - Kevin



  • Thomas Heller

    #2
    Re: limit module import to only certain symbols?

    "Kevin Howe" <khowe@perfnet. ca> writes:
    [color=blue]
    > Say I have the following module named "mymodule"
    >
    > import string
    > var1 = 'a'
    > var2 = 'b'
    >
    > And I want to import its symbols into another script:
    >
    > from mymodule import *
    >
    > This will import 3 symbols (string, var1, var2)
    >
    > Is it possible to limit it so that import * will only import specified
    > items? So that:
    >
    > from mymodule import *
    >
    > Would import only var1 and var2?[/color]

    You have to write

    __all__ = ["var1", "var2"]

    in your mymodule.

    Thomas

    Comment

    Working...