我从QtextEdit得到一些“代码”,我的意思是:
1, A, B, D, 1
1, B, B, D, 2
2, A, C, G, 1
我想买一本字典:
table={'1':{'A':['B', 'D', '1'], 'B':[B, D, 2]}, '2':{A:['C', 'G', '1']}
然后访问它:Var=table[1][A][B]
但我的表是:PyQt4.QtCore.QStringList
对象位于0xb50094c4
我得到了错误:
^{pr2}$问题来自QStringList
格式?在
def initMachine(self):
etat1=self.etat_1.text()
b = self.Table.toPlainText()
c=self.TM.obtenir_table(b)
print c
def obtenir_table(self, code):
code=str(code)
self.a=code.split("\n")
table={}
for i in range(len(self.a)):
b=self.a[i].split(', ')
etat=b[0]
symbole=b[1]
if etat=='':
print "ligne %i" %(i+1) + " : erreur "
if not table.has_key(etat):
table[etat] = {}
if not table[etat].has_key(symbole):
table[etat][symbole]=b[2:]
else:
print "ligne %i" %(i+1) +" : already declare"
self.table=self.convert_dict(table)
def convert_dict(self, dictionary):
if not isinstance(dictionary, dict):
return dictionary
return dict((str(k), self.convert_dict(v))
for k, v in dictionary.items())
def execute_TM(self, table, ruban, etat1):
self.Ruban.position=1
self.table=unicode(table)
etatAct=str(etat1)
while etatAct != 'stop':
symb=self.Ruban.lire_cellules()
print symb
print table
nvSymb=self.table[etatAct][symb][0]
self.Ruban.ecrire(nvSymb)
if table[etatAct][symb][1]=='D':
self.Ruban.deplacement_droite()
if table[etatAct][symb][1]=='G':
self.Ruban.deplacement_gauche()
else:
print "erreur code deplacement"
etatAct=table[etatAct][symb][2]
我试过很多不同的东西,这里是我尝试过的最后一个版本。。。。在
谢谢你的帮助!在
我发现问题来自于我为执行函数
execute_TM
,table
不是dict
的参数。在输入错误
谢谢让·弗朗索瓦!在
相关问题 更多 >
编程相关推荐