地圖這是我的代碼:如何將字符串使用python
a= ''' ddwqqf{x}'''
def b():
...
c=b(a,{'x':'!!!!!'})
print c
我想ddwqqf!!!!!
,
所以如何建立b
功能,
感謝
已更新:
但如何做這件事情:
a= ''' ddwqqf{x},{'a':'aaaa'}'''
c = a.format(x="!!!!!")
d= open('a.txt','a')
d.write(c)
它顯示錯誤:
Traceback (most recent call last):
File "d.py", line 8, in <module>
c = a.format(x="!!!!!")
KeyError: "'a'"
updated2:
這是字符串:
'''
{
'skill': {x_1},
'power': {x_2},
'magic': {x_3},
'level': {x_4},
'weapon': {
0 : {
'item': {
'weight': 40,
'target': 1,
'defence': 100,
'name': u'\uff75\uff70\uff78\uff7f\uff70\uff84',
'attack': 100,
'type': 1
},
},
1 : {
'item': {
'weight': 40,
'target': 1,
'defence': 100,
'name': u'\uff75\uff70\uff78\uff7f\uff70\uff84',
'attack': 100,
'type': 1
},
},
2 : {
'item': {
'weight': 40,
'target': 1,
'defence': 100,
'name': u'\uff75\uff70\uff78\uff7f\uff70\uff84',
'attack': 100,
'type': 1
},
}
......
}
}
'''
'a ='''ddwqqf {x}''' – JHSaunders 2011-03-18 10:37:23
你想達到什麼目的?你的第二個例子很混亂。 – 2011-03-18 10:41:51
我想將許多不同的變量映射成字典,並創建許多像這樣的字典。 – zjm1126 2011-03-18 11:04:24