问题
I'm quite new to Python and was having some confusing issues. I have two scripts main.py and second.py. I have a base url that needs to be changed in the second.py see bellow example
def getVarientStock(self, sku,base="http://www.baseurl.com"):
urlVariantStock = base + '/Product-GetVariants?pid=' + sku
r = requests.get(urlVariantStock, headers=self.headers)
try:
versions = json.loads(r.text)['variations']['variants']
except:
if r.status_code == 404:
return {'error' : '"' + self.sku + '" is an invalid SKU!'}
else:
return {'error' : 'There was an error checking Stock, make sure the SKU is correct and try again.'}
return
Now in main.py I am trying to figure out how I can have multiple different checkboxes to assign different base url's. I beleive the issue I am having is because it is a local variable?? second.py is imported into main.py.
This is the checkbox
is_checked = IntVar()
self.aucheck = Checkbutton(self.master, text='AU', onvalue=1, offvalue=0, variable=is_checked)
self.aucheck.pack(in_=top, side=LEFT)
And this is the funciton that I'm trying to figure out
def callcheckbox(self,):
if(is_checked.get()):
getVarientStock.base =("XX","http://www.adidas.com.au/on/demandware.store/Sites-adidas-AU-Site/en_AU")
Really appreciate the assistance!! Sorry if this is a silly question Im still learning
来源:https://stackoverflow.com/questions/41655700/issues-with-changing-variable-using-checkbox