'Is there a way to import all functions(using *) from a file without the imports of that file?
I have two .py files
Helper.pySomeClass.py
lets say for the example that both files import sys
I want to import into SomeClass.py the Helper.py like this: from helper.py import * (because I need all functions in it)
but I don't want to remove from any of the files the import sys because these two files aren't really go hand by hand.
is there a way to to import * and exclude the imports/from...import of another file?
Solution 1:[1]
You can define the __all__ module.
In your Helper.py file, add a line
__all__ = ["foo", "bar"] # All the objects you want to export
Then in SomeClass.py just use from helper.py import *, this will only import what is specified in __all__.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Raida |
