Python dotenv 模块,Dotenv() 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用dotenv.Dotenv()

项目:cookiecutter-django-reactjs    作者:genomics-geek    | 项目源码 | 文件源码
def main():
    if not os.path.exists('.env'):
        print('ERROR!! .env file is missing!')
        print("Please copy 'env.example' to '.env' and add appropriate values")
        exit()
    command = ['eb', 'setenv']
    failures = []
    for key, value in dotenv.Dotenv('.env').items():
        if key.startswith('POSTGRES'):
            print('Skipping POSTGRES values - Amazon RDS provides these')
            continue
        if value:
            command.append("{}={}".format(key, value))
        else:
            failures.append(key)
    if failures:
        for failure in failures:
            print("{} requires a value".format(failure))
    else:
        print(' '.join(command))
        check_call(command)
项目:aws_ir-api    作者:ThreatResponse    | 项目源码 | 文件源码
def __init__(self, sort_key):
        try:
            env = Dotenv('./.env')
            credential_table = env["CREDENTIAL_TABLE_ARN"]
        except IOError:
            try:
                env = Dotenv('../.env')
                credential_table = env["CREDENTIAL_TABLE_ARN"]
            except:
                credential_table ="arn:aws:dynamodb:us-west-2:576309420438:table/dev_credential"

        self.sort_key = sort_key
        self.table_name = credential_table.split('/')[1]
        self.dynamodb = None