lundi 16 décembre 2019

How to write an If else condition to choose between two functions

Scenario: I have a file project.py whose job is to navigate to another folder to get the environment variables stored in a .yml file. There are two cases here, one job is to navigate to a directory and another to navigate to a directory in an egg file for which I've used zipfile module. How do I include both the cases in project.py and write an if else condition to pick between those two functions based on the directory type. Below is the code. I'm fairly new to programming, would greatly appreciate any help.

project.py

Class Proj(dict):

def __init__(self, envmt, app_path):

        self.config_dict = {}
        self.envmt = envmt
        with zipfile.Zipfile("C:/Users/project/poc/dist/project-1.0.0-py3.6", 'r') as myzip:
            config = load(myzip.open("base.yml_path"))
        for key, value in config.items():
             configvals = value
        for key in configvals:
             self.config_dict[key]= configvals[key]

        self.base = config
        with zipfile.Zipfile("C:/Users/project/poc/dist/project-1.0.0-py3.6", 'r') as myzip:
            config = load(myzip.open("env.yml_path"))

        for key, value in config.items():
             configvals = value
        for key in configvals:
             self.config_dict[key]= configvals[key]
        self.env = config

def __init__(self, envmt, app_path):

        self.config_dict = {}
        self.envmt = envmt
        with open(os.path.join(app_path, 'config', 'base.yml'), 'r') as cfile:
            config = load(cfile)
        for key, value in config.items():
             configvals = value
        for key in configvals:
             self.config_dict[key]= configvals[key]

        self.base = config
        with open(os.path.join(app_path, 'config', envmt+'.yml'), 'r') as cfile:
            config = load(cfile)

        for key, value in config.items():
             configvals = value
        for key in configvals:
             self.config_dict[key]= configvals[key]
        self.env = config

How can I write a condition to choose between the above two functions.

Aucun commentaire:

Enregistrer un commentaire