2
I want to create a file called config.py
and put some settings inside a dictionary for whenever you need to invoke these parameters.
But how I call this parameter in Python?
For example, I will create the class Config
.
class Config:
@classmethod
def getConfig(self):
parameters = {
'url_m' : 'domain',
'url_ws_m' : 'domain.api',
'url_get_token' : 'domain.token',
'url_external_access' : 'external',
'name_ws_m' : 'service'
}
return parameters
In the other app I did so:
from pp.core.Config import *
.
.
.
a = Config().getConfig()['url_m']
That’s how it worked. But there is a more elegant method of importing the class with the method or this is the most correct way even?
Where is this config.py?
– Miguel
I created in a folder.
– Diego Souza
Where did you create it? At the root? inside the
main app
? in another app? Maybe it would help if you put the structure as it is now– Miguel
I created inside the core folder inside the main folder of the project.
– Diego Souza
It would be legal if you used configparser: https://docs.python.org/3/library/configparser.html
– Franklin Timóteo