【发布时间】:2017-03-24 03:38:38
【问题描述】:
我有这个代码
python_data_struct = {
'amazon_app_id': amazon_app_id,
'librivox_rest_url': librivox_rest_url,
'librivox_id': librivox_id,
'top': top,
'pacakge': 'junk',
'version': 'junk',
'password': password,
'description': description,
'long_description': long_description,
'make_audiobook::sftp_script::appname': '\"%{::appname}\"'
}
try:
myyaml = yaml.dump(python_data_struct)
except:
e = sys.exc_info()[0]
print "Error on %s Error [%s]" % ( librivox_rest_url, e )
sys.exit(5)
write_file( myyaml, hiera_dir + '/' + appname + '.yaml' );
它输出如下所示的 yaml:
{amazon_app_id: junk, description: !!python/unicode ' Riley was an American writer
known as the "Hoosier poet", and made a start writing newspaper verse in Hoosier
dialect for the Indianapolis Journal in 1875. His favorite authors were Burns
and Dickens. This collection of poems is a romanticized and mostly boy-centered
paean to a 19th century rural American working-class childhood. (Summary by Val
Grimm)', librivox_id: '1000', librivox_rest_url: 'https://librivox.org/api/feed/audiobooks/id/1000/extended/1/format/json',
long_description: !!python/unicode "\n Riley was an American writer known as the\
\ \"Hoosier poet\", and made a start writing newspaper verse in Hoosier dialect\
\ for the Indianapolis Journal in 1875. His favorite authors were Burns and Dickens.\
\ This collection of poems is a romanticized and mostly boy-centered paean to\
\ a 19th century rural American working-class childhood. (Summary by Val Grimm)\n\
\nThe \"Selected Riley Child-Rhymes\" App will not use up your data plan's minutes\
\ by downloading the audio files (mp3) over and over. You will download load all\
\ the data when you install the App. The \"Selected Riley Child-Rhymes\" App works\
\ even in airplane mode and in places without Wi-Fi or phone network access! So\
\ you can listen to your audio book anywhere anytime! The \"Selected Riley Child-Rhymes\"\
\ App automatically pauses when you make or receive a phone call and automatically\
\ resumes after the call ends. The \"Selected Riley Child-Rhymes\" App will continue\
\ to play until you exit the App or pause the reading so it is perfect for listening\
\ in bed, at the gym, or while driving into work.\" \n", 'make_audiobook::sftp_script::appname': '"%{::appname}"',
pacakge: junk, password: junk, top: junk, version: junk}
很难看出,但有问题的特定键/值对是这个:
'make_audiobook::sftp_script::appname': '"%{::appname}"',
我需要它是这样的:
'make_audiobook::sftp_script::appname': "%{::appname}",
只是在%{::appname} 周围加上双引号我不知道在我的python 代码中要做什么。请帮忙:)
【问题讨论】: