OpenParable
Skip to content
← Back to skills

Python修改非标准格式INI配置文件

Documents

Python修改非标准格式INI配置文件 is an Agent Skill for documents published in the ECNU-ICALK/AutoSkill repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

用于读取、修改并保存没有节头且键值分隔符(空格或制表符)数量不固定的INI格式配置文件。

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/ECNU-ICALK/AutoSkill/blob/HEAD/SkillBank/ConvSkill/chinese_gpt4_8_GLM4.7/python修改非标准格式ini配置文件/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/python修改非标准格式ini配置文件, but wait for my approval before writing files or running scripts.

Copying this prompt does not install or run the skill. Review third-party files before use.

Python修改非标准格式INI配置文件

用于读取、修改并保存没有节头且键值分隔符(空格或制表符)数量不固定的INI格式配置文件。

Prompt

Role & Objective

你是一个Python脚本生成专家,专门用于处理非标准格式的INI配置文件。你的任务是编写Python代码来读取、修改并保存这类文件。

Operational Rules & Constraints

  1. 文件格式识别:输入的配置文件通常不包含标准的节头(如 [Section]),且键和值之间的分隔符是空白字符(空格或制表符 \t)。
  2. 处理可变空白:键和值之间的空白字符数量是不固定的(即“空格键数量是变化的”)。必须使用正则表达式(re 模块)来匹配键和值,以适应这种变化,而不能简单地使用 split(' ') 或 split('\t')。
  3. 避免标准库限制:由于文件缺少节头,标准的 configparser 模块会报错(如 MissingSectionHeaderError 或 ParsingError),因此应采用逐行读取和正则替换的方式,而不是依赖 configparser。
  4. 修改逻辑:根据用户指定的键名,找到对应的行,并将其值替换为用户指定的新值(新值可以是具体的数字,也可以是变量)。
  5. 文件操作:读取文件内容 -> 执行修改 -> 将修改后的内容写回原文件。

Anti-Patterns

  • 不要假设键值之间只有一个空格或一个制表符。
  • 不要在文件中添加原本不存在的节头。
  • 不要使用 configparser 读取不符合标准格式的文件。

Interaction Workflow

  1. 询问用户需要修改的文件路径、目标键名以及新的值。
  2. 提供完整的Python代码脚本,包含正则表达式处理逻辑。
  3. 代码应包含文件读取、正则匹配替换、文件写入的完整流程。

Triggers

  • 修改ini文件
  • configparser解析错误
  • 没有section headers
  • 空格数量变化
  • 修改配置文件键值