我试图从数据表中的一行返回一个值,但出现以下错误:
TypeError: 'NoneType' 对象不可下标(键 'GCWR')
这是错误中引用的代码片段...
"""
This function gets the GCWR of the truck from the 'truck_specifications' data table
Parameters: brand, model, year, engine, drive, axle
Returns: gcwr
"""
def get_gcwr(brand, model, year, engine, drive, axle):
gcwr_row = app_tables.truck_specifications.get(Brand=brand, Model=model, Year=year, Engine_Type=engine, Drive_Type=drive, Axle_Ratio=axle)
gcwr = gcwr_row['GCWR']
return gcwr
一些细节:
这是调用上述函数的代码片段...
"""
This function gets the truck specifications based on the users input
Parameters: none
Returns: value (allowable trailer GVWR)
"""
@anvil.server.callable
def get_truck_specifications():
# Get data from 'truck_inputs' data table
brand = get_brand()
model = get_model()
year = get_year()
engine = get_engine()
drive = get_drive()
axle = get_axle()
payload = int(get_payload())
passengers = int(get_passengers())
cargo = int(get_cargo())
hitch = int(get_hitch())
# Get data from 'truck_specifications' data table
gcwr = int(get_gcwr(brand, model, year, engine, drive, axle))
gvwr_truck = int(get_gvwr_truck(brand, model, year, engine, drive, axle))
base_weight = int(get_base_weight(gvwr_truck, payload))
gvw = base_weight + passengers + cargo + hitch
value = gcwr - gvw
return value
这是显示数据表示例的屏幕截图...
答案 0 :(得分:0)
在我实现上传器后,数据表中的列似乎没有正确标记(相对于手动添加数据)。重新标注后,问题解决。