强制 YAML 值是字符串 [英] Force YAML values to be strings

查看:34
本文介绍了强制 YAML 值是字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看这段代码,在 Python 2.7 下:

<预><代码>>>>导入 yaml>>>yaml.load('字符串:01'){'字符串':1}>>>:(

是否可以在不修改yaml文件的情况下获取字符串01?我在文档中没有找到任何内容.

解决方案

尝试:

<代码>>>导入 yaml>>yaml.load('string: 01', Loader=yaml.loader.BaseLoader){u'string': u'01'}

Look at this code, under Python 2.7:

>>> import yaml
>>> yaml.load('string: 01')
{'string': 1}
>>> :(

Is it possible to obtain the string 01 without modifying the yaml file? I didn't find anything in the docs.

解决方案

Try:

>> import yaml
>> yaml.load('string: 01', Loader=yaml.loader.BaseLoader)
{u'string': u'01'}

这篇关于强制 YAML 值是字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆