Read a text file and save value as variable in python
This question already has an answer here:
如果您只想与其他功能共享,请使用全局功能
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/23886.html
上一篇: Python加密函数和全局变量