读取一个文本文件并将值作为变量保存在python中
这个问题在这里已经有了答案:
如果您只想与其他功能共享,请使用全局功能
id = 0
def main():
global id
...
id = 0 # declare it in the global scope
def main():
# using the global keyword will let you access it in the function scope
global id
input = file(infile, 'r')
lines = input.readlines()
input.close()
i = 0
for line in lines:
i += 1
id = int(line)
WorkOnIDThread(id)
main()
print id
链接地址: http://www.djcxy.com/p/23885.html