Reputation: 17
I have a script that have multiple files and a config file with all the variables store in one Python file.
Folder structure:
Config file:
If I try to run the main file which calls the head
function imported, an error pops up saying that the config cannot be imported.
Imports:
Upvotes: 1
Views: 4063
Reputation: 841
Your Functions folder has a __init__.py file. If your app executes from Main.py (ie if Main.py satisfies __name__ == "__main__"
) therefore wherever you are in your app you could import the config like this:
from Functions.Config import *
However,from module import *
is not recommended with local import. You could give an alias to the import and call name.variable
instead of calling name
directly.
Example:
def head():
# import packages
import Function.Config as conf
print(conf.more_200)
head()
>>> 50
Upvotes: 1
Reputation: 1814
Your syntax are wrong.
It is supposed to be from Config import *
and not import .Config import *
Upvotes: 0