第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Python yaml 在引號中生成幾個值

Python yaml 在引號中生成幾個值

回首憶惘然 2021-06-17 14:00:39
我yaml在 Python 腳本中使用該模塊生成 YAML 文件。下面是一個例子:import yamlclass MyDumper(yaml.Dumper):    def increase_indent(self, flow=False, indentless=False):        return super(MyDumper, self).increase_indent(flow, False)foo = {    'instance_type': 'test',    'hostname': "\"testhost\"",    'name': 'foo',    'my_list': [        {'foo': 'test', 'bar': 'test2'},        {'foo': 'test3', 'bar': 'test4'}],    'hello': 'world',}print yaml.dump(foo, Dumper=MyDumper, default_flow_style=False)輸出:hello: worldhostname: '"testhost"'instance_type: testmy_list:  - bar: test2    foo: test  - bar: test4    foo: test3name: foo在上面的輸出主機名值有單引號和雙引號,我只想要雙引號。預期輸出:hello: worldhostname: "testhost"instance_type: testmy_list:  - bar: test2    foo: test  - bar: test4    foo: test3name: foo
查看完整描述

3 回答

?
12345678_0001

TA貢獻1802條經(jīng)驗 獲得超5個贊

你得到雙引號,因為那是你的輸入數(shù)據(jù)。這一行:

'hostname': "\"testhost\"",

說你想要hosthame一個以 開頭和結尾的 10 個字符的字符串作為值",這就是你在 yaml 中看到的。這個帶有轉義雙引號的字符串"\"testhost\""和 yaml 版本'"testhost"'是相同數(shù)據(jù)的兩種不同的源代碼表示。如果要在其中嵌入特殊字符(例如\n換行符),則只需要在 yaml 中的字符串周圍加上雙引號。但yaml.dump()會為你照顧。


查看完整回答
反對 回復 2021-06-22
  • 3 回答
  • 0 關注
  • 283 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號