Reputation: 21
I hav egot problem with string
'replication = {\'class\' : \'NetworkTopologyStrategy\', \'datacenter1\' : {}};'.format(N)
Why does it return:
replication = \{\'class\' : \'NetworkTopologyStrategy\', \'datacenter1\': {} };'.format(N)
KeyError: "'class' "
Upvotes: 1
Views: 43
Reputation: 81594
Formatting a string that contains arbitrary {}
can be funky.
In this case you'd need to surround the entire string in additional {}
in order to escape the {
and }
that should be ignored by format
:
N = 'xxx'
print('replication = {{\'class\' : \'NetworkTopologyStrategy\', \'datacenter1\' : {}}};'
.format(N))
# replication = {'class' : 'NetworkTopologyStrategy', 'datacenter1' : xxx};
Upvotes: 1