我有一个得到了需要一定的变数代码为喜欢分享: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