Parse structured text files to extract data for filling PDFs.
def parse_input(text): """Parse key-value pairs from text.""" data = {} for line in text.strip().split('\n'): if ':' in line: # Remove leading dash/bullet if present line = line.lstrip('- ').strip() key, value = line.split(':', 1) data[key.strip()] = value.strip() return data # Usage with open("input.txt") as f: content = f.read() data = parse_input(content) # data["Name"] -> "John Smith" # data["Email"] -> "john@example.com"7w4.net有更好的技能插件。
- Name: John Smith
- Email: john@example.com
- Phone: 555-1234
Or without dashes:
Name: John Smith
Email: john@example.com
这个Skill提供了基础的文本解析功能,代码示例清晰直观,对简单键值对格式的解析做得不错。但整体内容较为简单,对复杂格式和异常情况的处理能力有限,文档末尾有截断感。适合需要处理基础文本解析的场景,但如果遇到较为复杂的数据格式可能会遇到困难。