請問我有個架構如下,start1底下的fun1~fun3跟start2底下的fun1~fun3
是完全一樣的內容
def start1():
fun1():
fun2():
fun3():
a1='xxx'
a2='xxx'
a3='xxx'
def start2():
fun1():
fun2():
fun3():
fun4():
a1='xxx'
a2='xxx'
a3='xxx'
這樣在維護上會很麻煩,等於修改funX要一次改兩個地方,後來改成這樣測試,
但延伸一個全域變數的問題。因funX都會取用a1~a3變數,改完後勢必要把
a1~a3套global才能餵給funX,因為只是舉例沒列太多,實際上變數有數十個
有看到相關文章說global濫用會造成debug困難,這樣該如何避免funX重複
與global的濫用呢 謝謝
def fun1():
def fun2():
def fun3():
def fun4():
def start1():
fun1()
fun2()
fun3()
global a1
global a2
global a3
a1='xxx'
a2='xxx'
a3='xxx'
def start2():
fun1()
fun2()
fun3()
fun4()
global a1
global a2
global a3
a1='xxx'
a2='xxx'
a3='xxx'