Documentation v0.1.0

yaml-config

Use this skill when reading or writing YAML configuration files, loading vehicle parameters, or handling config file...

wu 更新于 2026-04-13 1 浏览
下载 SKILL

技能说明

Use this skill when reading or writing YAML configuration files, loading vehicle parameters, or handling config file parsing with proper error handling.

使用场景

Use this skill when reading or writing YAML configuration files, loading vehicle parameters, or handling config file parsing with proper error handling.

直接复制以下提示词,发送给你的 AI 助手即可完成安装。

帮我下载并安装这个SKILL:https://skillhub.cstcloud.cn/download/yaml-config
  1. 点击上方「下载 SKILL」按钮,获取技能压缩包。
  2. 将压缩包解压到你的 Agent 技能目录。
  3. 重启客户端后即可在技能列表中选择该技能。

技能文件内容

4 个文件 · 14 kB
SKILL.md text/markdown
---
name: yaml-config
description: Use this skill when reading or writing YAML configuration files, loading vehicle parameters, or handling config file parsing with proper error handling.
---

# YAML Configuration Files

## Reading YAML

Always use `safe_load` to prevent code execution vulnerabilities:

```python
import yaml

with open('config.yaml', 'r') as f:
    config = yaml.safe_load(f)

# Access nested values
value = config['section']['key']
```

## Writing YAML

```python
import yaml

data = {
    'settings': {
        'param1': 1.5,
        'param2': 0.1
    }
}

with open('output.yaml', 'w') as f:
    yaml.dump(data, f, default_flow_style=False, sort_keys=False)
```

## Options

- `default_flow_style=False`: Use block style (readable)
- `sort_keys=False`: Preserve insertion order
- `allow_unicode=True`: Support unicode characters

## Error Handling

```python
import yaml

try:
    with open('config.yaml', 'r') as f:
        config = yaml.safe_load(f)
except FileNotFoundError:
    config = {}  # Use defaults
except yaml.YAMLError as e:
    print(f"YAML parse error: {e}")
    config = {}
```

## Optional Config Loading

```python
import os
import yaml

def load_config(filepath, defaults=None):
    """Load config file, return defaults if missing."""
    if defaults is None:
        defaults = {}

    if not os.path.exists(filepath):
        return defaults

    with open(filepath, 'r') as f:
        loaded = yaml.safe_load(f) or {}

    # Merge loaded values over defaults
    result = defaults.copy()
    result.update(loaded)
    return result
```

文件内容直接读取自技能仓库,仅供安装前审阅;以实际下载的压缩包为准。