I have 2 environment and one of the environment is clusterdisabled, the other is cluster enabled. To handle this, i added a key in config For one of the environment it's
redis_class = "Redis"
The other environment has
redis_class = "RedisCluster"
init.py
from myapp.config import config
#this printed the value
print(config["redis_class")
redis_class = config["redis_class"]
from redis import redis_class as Redis
The last line in init.py is throwing an error. How do I import classes from config?
Thanks in advance
You can try out something like this,
or keep the above code in another file(
config.py) and in your main file you can import it directly.like
from config import RedisWithout using
if-conditionyou can try withgetattrlike this