我想从test1.py中的test.py中定义调用Branchname并运行到以下错误,任何人都可以提供输入吗?在不同的python模块中调用参数
test.py
import test1
import os
import sys
def main():
#initialize global variables & read CMD line arguments
global BranchName
ScriptDir = os.getcwd()
print ScriptDir
BranchName = sys.argv[1]
print "BranchName"
print BranchName
#Update input file with external gerrits, if any
print "Before running test1"
test1.main()
print "After running test1"
if __name__ == '__main__':
main()
test1.py
import test
def main():
print test.BranchName
运行到以下错误
BranchName
ab_mr2
Before running test1
Traceback (most recent call last):
File "test.py", line 18, in <module>
main()
File "test.py", line 14, in main
test1.main()
File "/local/mnt/workspace/test1.py", line 3, in main
print test.BranchName
AttributeError: 'module' object has no attribute 'BranchName
您在这里有一个圆形的进口,这是从来没有好。代码是这样分裂的吗? –
@BurhanKhalid - 我的目标是打印从test1.py传递给test.py的BranchName。 – user2341103
你没有在这里传递任何东西。 –