我想從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
你沒有在這裏傳遞任何東西。 –