您好我在使用python 3.6中的现有函数制作速率函数时遇到问题我不断收到错误TypeError: float() argument must be a string or a number, not 'StringVar'
或TypeError: can't multiply sequence by non-int of type 'Tag'
。我通常在做这类事情时没有任何问题。
这是第一个功能。
def results():
if running:
cur1 = listbox1.get('active')
cur2 = listbox2.get('active')
t = datetime.utcnow()
url1 = "http://www.xe.com/currencyconverter/convert/" + "?Amount=" + amountex + "&From=" + cur1 + "&To=" + cur2
url2 = "http://www.xe.com/currencyconverter/convert/" + "?Amount=" + amountex + "&From=" + cur2 + "&To=" + cur1
html_code1 = requests.get(url1).text
html_code2 = requests.get(url2).text
soup1 = BeautifulSoup(html_code1, 'html.parser')
soup2 = BeautifulSoup(html_code2, 'html.parser')
rate1 = soup1.find('span', {'class', 'uccResultAmount'})
rate2 = soup2.find('span', {'class', 'uccResultAmount'})
lblfrmex_text.set(rate2.contents[0])
lbltoex_text.set(rate1.contents[0])
lbldatetime_text.set(t)
#Then do a whole bunch of calculations.
这就是我的尝试。
def getrates(curA, curB):
url1 = "http://www.xe.com/currencyconverter/convert/" + "?Amount=" + amountex + "&From=" + curA + "&To=" + curB
url2 = "http://www.xe.com/currencyconverter/convert/" + "?Amount=" + amountex + "&From=" + curB + "&To=" + curA
html_code1 = requests.get(url1).text
html_code2 = requests.get(url2).text
soup1 = BeautifulSoup(html_code1, 'html.parser')
soup2 = BeautifulSoup(html_code2, 'html.parser')
rate1 = soup1.find('span', {'class', 'uccResultAmount'})
rate2 = soup2.find('span', {'class', 'uccResultAmount'})
lblfrmex_text.set(rate2.contents[0])
lbltoex_text.set(rate1.contents[0])
return lblfrmex_text, lbltoex_text
def results():
if running:
cur1 = listbox1.get('active')
cur2 = listbox2.get('active')
t = datetime.utcnow()
lbldatetime_text.set(t)
#Get cur1/cur2 exrates
var1 = getrates(cur1, cur2)
var2 = (var1[0])
var3 = (var1[0])
rate1contents = float(var2)
rate2contents = float(var3)
print (rate1contents)
我几乎知道我,但我似乎无法看到我哪里出错了?
任何帮助都将不胜感激。