如何在python中定义全局列表并将本地列表附加到它 [英] How to define a global list in python and append local list to it
本文介绍了如何在python中定义全局列表并将本地列表附加到它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想定义一个全局列表并将一个列表附加到该列表.我正在获取一些单击事件的列表(i [0]),并将其附加到mnum_list.现在,我想创建一个全局列表,并将该mnum_list附加到该列表.知道怎么做吗?
I want to define a global list and append a list to it. I am getting a list (i[0]) by some on click event and appended that to mnum_list. Now i want create a global list and append that mnum_list to it. Any idea how to do this?
def OnClick(self, event):
name = event.GetEventObject().GetLabelText()
cursor= self.conn.execute("SELECT * FROM ELEMENT where SYMBOL==?", (name,))
elements = cursor.fetchall()
print elements
cursor= self.conn.execute("SELECT ATOMIC_NUMBER FROM ELEMENT where SYMBOL = ?", (name,))
numbers = cursor.fetchone()[0]
print numbers
atomicnumber = numbers
cursor= self.conn.execute("SELECT MOL_NUMBER FROM LINK where ELEMENT_NUMBER = ?", (atomicnumber,))
mnumbers = cursor.fetchall()
print mnumbers
mnum_list = []
for i in mnumbers:
mnum_list.append(i[0])
print mnum_list
推荐答案
如果没有赋值,则global
语句中就没有必要了,只是:
There is no need in global
statement if there is no assignment, just:
def foo(x):
sublist = range(x)
glist.append(sublist)
,如果是扩展名:
def foo(x):
sublist = range(x)
glist.extend(sublist)
这篇关于如何在python中定义全局列表并将本地列表附加到它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文