0
我想輸出一個我打算使用「hiera」的yaml文件。我想輸出的東西,看起來像這樣:不支持的格式字符'{'
---
top: '/tmp'
package: 'mypackage'
version: 1
password: 'cubswin:)'
make_audiobook::package_name: "%{hiera('package')}"
make_audiobook::version: "%{hiera('version')}"
make_audiobook::mp3filesdir: "%{hiera('top')}/%{::appname}/%{::appname}/res/raw"
make_audiobook::app_image::app_image_url: 'http://big/long/path'
make_audiobook::app_image::resource_path: "%{hiera('top')}/%{::appname}/%{::appname}"
make_audiobook::app_javacode::appname: "%{::appname}"
make_audiobook::app_javacode::password: "%{hiera('password')}"
make_audiobook::app_javacode::apptitle: "The Title of The App"
make_audiobook::app_javacode::package: "%{hiera('package')}"
make_audiobook::app_javacode::path_to_code: "%{hiera('top')}/%{::appname}/%{::appname}/src/com/%{hiera('package')}/%{::appname}"
make_audiobook::app_javacode::path_to_androidmanifest: "%{hiera('top')}/%{::appname}/%{::appname}"
make_audiobook::app_javacode::version: "%{hiera('version')}"
所以,我想這個...
print """
---
top: '%s'
package: '%s'
version: %s
password: '%s'
make_audiobook::package_name: "%{hiera('package')}"
make_audiobook::version: "%{hiera('version')}"
make_audiobook::mp3filesdir: "%{hiera('top')}/%{::appname}/%{::appname}/res/raw"
make_audiobook::app_image::app_image_url: '%s'
make_audiobook::app_image::resource_path: "%{hiera('top')}/%{::appname}/%{::appname}"
make_audiobook::app_javacode::appname: "%{::appname}"
make_audiobook::app_javacode::password: "%{hiera('password')}"
make_audiobook::app_javacode::apptitle: "%s"
make_audiobook::app_javacode::package: "%{hiera('package')}"
make_audiobook::app_javacode::path_to_code: "%{hiera('top')}/%{::appname}/%{::appname}/src/com/%{hiera('package')}/%{::appname}"
make_audiobook::app_javacode::path_to_androidmanifest: "%{hiera('top')}/%{::appname}/%{::appname}"
make_audiobook::app_javacode::version: "%{hiera('version')}"
make_audiobook::app_javacode::tracks:
""" % (top, package, version, app_image_url, apptitle)
但我得到這個錯誤:
Traceback (most recent call last):
File "./get_track_titles.py", line 54, in <module>
""" % (top, package, version, app_image_url, apptitle)
ValueError: unsupported format character '{' (0x7b) at index 88
您可能想嘗試轉義'%'和'{}'字符,並且您錯過了'password' – Skycc
它是'%%'在格式字符串中轉義'%'。 –
@Skycc,'{}'不需要在這裏轉義。 –