468,471 Members | 1,638 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,471 developers. It's quick & easy.

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

Jul 18 '05 #1
1 3474
"Kevin Howe" <kh***@perfnet.ca> writes:
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
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Paul Rubin | last post: by
4 posts views Thread by Brad Tilley | last post: by
9 posts views Thread by Sean | last post: by
5 posts views Thread by sophie_newbie | last post: by
2 posts views Thread by Keith Jackson | last post: by
6 posts views Thread by dudeja.rajat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.