我在申报名单时遇到了一些问题。似乎我无法删除列表中的所有元素。在reset_a
打印输出中,它显示一个空列表,但在myFunction
中再次检查列表后,上一个元素仍在列表中。如何声明全局列表并在其他定义的列表中使用它?
a = []
def reset_a():
global a
del a[:]
print a
def myFunction():
global a
#check other stuffs........... then..
print a
if data not in a:
a.append(data)
time.sleep(5)
reset_a()
if __name__=='__main__':
while True:
myFunction()
编辑:我找到了一种方法来完成它。
global a
a = []
def reset_a():
del a[:]
print a
def myFunction():
#check other stuffs...........and get 'data' then..
print a
if data not in a:
a.append(data)
time.sleep(5)
reset_a()
if __name__=='__main__':
while True:
myFunction()
只有新的
data
不在a
中时,才会执行rest_a()
相关问题 更多 >
编程相关推荐