我有一个 python 脚本,它想读取一组 conda 食谱并用一些信息更新它们(例如文件:https ://github.com/williamjamir/staged-recipes/blob/850760fb63c0fc000b95ac27680ec018fa94dcb7/recipes/pyexcel-ezodf/meta .yaml):
我正在使用这个:
from ruamel.yaml import YAML
from yaml.constructor import ConstructorError
from yaml.scanner import ScannerError
yaml = YAML(typ='jinja2')
yaml.allow_duplicate_keys = True
with open(file_name) as fp:
yalm_file = yaml.load(fp)
当我使用以下方法打印原始文件时yaml_file
:
with open(path_file, 'w') as fp:
yaml.dump(yaml_file, fp, allow_unicode=True, explicit_start=True)
输出包含许多与数据类型相关的标签和注释,例如:
--- !!python/object/apply:ruamel.yaml.comments.CommentedMap
dictitems:
about: !!python/object/apply:ruamel.yaml.comments.CommentedMap
dictitems: {home: 'https://github.com/soedinglab/xxmotif', license:
GPLv3, license_file: LICENSE,
summary: 'eXhaustive, weight matriX-based motif discovery in nucleotide sequences'}
state:
_yaml_format: !!python/object/new:ruamel.yaml.comments.Format
state: !!python/tuple
- null
- {_flow_style: false}
我该如何解决这个问题?