> For the complete documentation index, see [llms.txt](https://gitbook.aiaod.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.aiaod.com/programming/python-ji-qiao/python-pei-zhi-wen-jian-guan-li.md).

# Python配置文件管理

如下面的配置，则如果环境变量里有这个配置，就使用环境变量里的，否则使用 config.yaml 文件里的

```python
import boto3  
import os  
import yaml  
  
  
class DefaultConfig:  
    aws_profile = os.getenv("AWS_PROFILE")  
    es_host = os.getenv("ES_HOST")  
    es_port = int(os.getenv("ES_PORT")) if os.getenv("ES_PORT") else None  
  
  
class Config(DefaultConfig):  
    def __init__(self):  
        with open("config.yaml", "r") as f:  
            self.config = yaml.safe_load(f)  
  
        for k, v in self.config.items():  
            if getattr(self, k, None) is None:  
                setattr(self, k, v)
```
