AttributeError: module 'yaml' has no attribute 'load'
时间: 2023-09-20 08:07:28 浏览: 152
This error occurs when you are trying to use the `load` function from the `yaml` module, but the module does not have this attribute.
In Python 3, the `load` function has been replaced by `safe_load`, which is a safer version of `load` that only allows loading of YAML files with basic datatypes such as strings, integers, and lists.
To fix the error, replace `load` with `safe_load` in your code:
```python
import yaml
# Load YAML file
with open('config.yaml', 'r') as file:
config = yaml.safe_load(file)
```
If you need to load YAML files with more complex datatypes such as dictionaries or custom classes, you can use the `load` function from the `ruamel.yaml` module instead:
```python
import ruamel.yaml
# Load YAML file
with open('config.yaml', 'r') as file:
config = ruamel.yaml.load(file, Loader=ruamel.yaml.Loader)
```