我有一个脚本调用一个函数,该函数采用十六进制数作为参数.参数需要0x前缀.数据源是一个数据库表,存储为字符串,因此返回"0x77".我正在寻找一种从数据库中获取字符串的方法,并将其用作带有0x前缀的十六进制形式的参数.
这有效:
addr = 0x77
value = class.function(addr)
Run Code Online (Sandbox Code Playgroud)
数据库条目必须是一个字符串,因为大多数其他记录在此列中没有十六进制值,但可以更改这些值以使其更容易,因此代替"0x77",它可能是"119".
我正在尝试自学python并遇到了一个我不确定的错误.错误看起来像这样:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.2/tkinter/__init__.py", line 1426, in __call__
return self.func(*args)
File "/home/pi/python/SolutionMixerGUI.py", line 39, in calculate
fgTotal = self.vol * fgML
TypeError: unsupported operand type(s) for *: 'type' and 'float'
Run Code Online (Sandbox Code Playgroud)
我知道这个错误告诉我,我不能将这两种类型相乘,我很困惑'类型'是什么.任何人都可以帮我清除这个错误.完整代码如下.
from tkinter import *
class App:
def __init__(self,master):
frame = Frame(master)
frame.pack()
Label(frame, text='Solution in liters:').grid(row=0, column=0)
self.vol = DoubleVar
Entry(frame, textvariable=self.vol).grid(row=0, column=1)
Label(frame, text='Growth Stage (1-5):').grid(row=1, column=0)
self.stage = IntVar
Entry(frame, textvariable=self.stage).grid(row=1, column=1)
self.fgTotal = DoubleVar
self.fmTotal = DoubleVar
self.fbTotal …Run Code Online (Sandbox Code Playgroud)