我有一個得到了需要一定的變數代碼爲喜歡分享:Python的 - 如何共享功能之間的變量(不使用全局變量)
def example(arg):
req = urllib2.Request(r'{}'.format(arg))
...
def exampe2(arg):
# i need this func to access req
# i think i can't use req as a global var since the program might need to get imported and it would run from main() (which is again a function)
真的想你的幫助!
您只需添加另一個參數 –
從'example'返回它,將它傳遞給'exampe2'。或者如果前者調用後者,直接傳遞它。 – jonrsharpe