我有两(2)个脚本如下:
test.py
from google.apputils import app
import gflags
FLAGS = gflags.FLAGS
gflags.DEFINE_string('flag1', 'Value 1', 'flag#1')
def main(argv):
FLAGS.flag1 = "Value2"
print 'Flag 1 has value: ' + FLAGS.flag1
if __name__ == '__main__':
app.run()
和 test1.py
from google.apputils import app
import test
def main(argv):
print 'Flag 1 has value: ' + test.FLAGS.flag1
if __name__ == '__main__':
app.run()
如何将更改的标志值从test.py传递给test1.py,这样我输出"标志1具有值:Value2" 在test1.py?
答案 0 :(得分:0)
我找到的解决方案如下:
<强> test.py 强>
from google.apputils import app
import subprocess
def main(argv):
entry = raw_input("Enter Value: ")
subprocess.Popen('python test1.py --flag1="' + entry + '"', shell=True)
if __name__ == '__main__':
app.run()
和 test1.py
from google.apputils import app
import gflags
gflags.DEFINE_string('flag1', None, 'Flag#1')
FLAGS = gflags.FLAGS
def main(argv):
print 'Flag 1 has value: ' + FLAGS.flag1
if __name__ == '__main__':
app.run()