首先这个函数是yaml模块的子集函数
import yaml
然后个人理解yaml.dump()函数,就是将yaml文件一次性全部写入你创建的文件。
官方给出的是这个样子:
def dump(data, stream=None, Dumper=Dumper, **kwds): """ Serialize a Python object into a YAML stream. If stream is None, return the produced string instead. """ return dump_all([data], stream, Dumper=Dumper, **kwds)
I can not understand it very well ,would you mind give me an example?please
of course:
代码:
#向你创建的这个 ./gyy.yaml 文件中写内容 with open("./gyy.yaml", 'w') as f: contain = {'年龄':"31", "性别":"女","籍贯":'北京'} yaml.dump(contain,f)
然后:生成一个gyy.yaml文件,里面内容为:
关于yaml.dump()函数的理解
最新推荐文章于 2024-07-23 14:36:35 发布