2010-09-20 80 views
20

如何格式化這樣的YAML文檔,以便PyYAML能夠正確解析它?在YAML中保留新行

Data: Some data, here and a special character like ':' 
     Another line of data on a separate line 

我知道「:」字符是特殊的,所以我必須圍繞整個事情的報價像這樣:

Data: "Some data, here and a special character like ':' 
     Another line of data on a separate line" 

而且爲了添加一個新行,我要補充「\ n」的

Data: "Some data, here and a special character like ':'\n 
     Another line of data on a separate line" 

反正是有格式文件YAML,所以我不必爲了有一個新行添加'\n的?

回答

29

對於多線標量,您可以使用塊。字符|表示塊的開始。用途:

Data: | 
     Some data, here and a special character like ':' 
     Another line of data on a separate line 
1

如果NullUserException的解決方案是添加額外的換行符是你應該使用一個問題:

Data: |- 
     Some data, here and a special character like ':' 
     Another line of data on a separate line