python - How to pass variables into next function without using global -
i'm looking how can take variables i've saved next function. illustrate mean, i'm getting latest version number online such:
try: webversion = urllib2.urlopen( "http://www." + server + "/version").read().rstrip() if webversion > version: update_files() elif version >= webversion: print "[system] have latest version: v." + version
in update_files()
function, take variable i've gained (webversion
, possibly version
) on next function.
i'm thinking of setting variable global:
try: global webversion webversion = urllib2.urlopen( "http://www." + server + "/version").read().rstrip() if webversion > version: update_files() elif version >= webversion: print "[system] have latest version: v." + version
is there better way/smarter this?
just pass arguments function:
function definition:
def update_files(webversion, version): # ... function execution
and code:
try: # global webversion don't need webversion = urllib2.urlopen("http://www." + server + "/version").read().rstrip() if webversion > version: update_files(webversion, version) elif version >= webversion: print "[system] have latest version: v." + version #and careful add except, try! except: print("error!")
Comments
Post a Comment