Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   limit module import to only certain symbols? (http://www.velocityreviews.com/forums/t318888-limit-module-import-to-only-certain-symbols.html)

Kevin Howe 06-26-2003 06:56 PM

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 06-26-2003 08:02 PM

Re: limit module import to only certain symbols?
 
"Kevin Howe" <khowe@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


All times are GMT. The time now is 12:37 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.