limit module import to only certain symbols?

K

Kevin Howe

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
 
T

Thomas Heller

Kevin Howe said:
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?

You have to write

__all__ = ["var1", "var2"]

in your mymodule.

Thomas
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top