在 Python 中加载 Yaml 文件而不转换为字典

Load Yaml file in Python without converting to dict

我需要将 yaml 文件的内容按原样存储到变量中(不转换为字典),或者在将其存储为字典后是否有任何方法可以恢复为 yaml 格式而不将其存储在文件中。我尝试使用 yaml.load(file) 其中 returns 字典中的对象。 有什么办法可以实现吗?

怎么样?

ymlFile = open('file.yml').read()

https://www.pythonforbeginners.com/files/reading-and-writing-files-in-python