我正在通过使用带有命名占位符的格式来进行多行变量替换
port = 2000
replicaset = 'test'
print('''
mongo --port {port} --eval '
rs.initiate(
{
_id: "{replicaset}",
version: 1,
members: [
{ _id: 0, host : "localhost:{port}", priority: 1, votes: 1 },
]
}
)
'
'''.format(replicaset=replicaset, port=port))
我得到的错误如下
21:55 user@machine [machine-tag] ~$ python mongodb-setup.py
Traceback (most recent call last):
File "mongodb-setup.py", line 59, in <module>
'''.format(replicaset=replicaset, port=port))
KeyError: '\n _id'