试图从同一文件夹中的另一个文件导入i Dictionary。
这是“流体”模块:
fluiddensitydict = {
"Acetone" : 791/1000,
"Ammonia" :604/1000,
"Benzene":879/1000,
"Butane":556/1000,
"CCL4":1584/1000,
"CO2":680/1000,
"Ethanol":783/1000,
"Ethyl_Acetate":902/1000,
"Gasoline":750/1000,
"Glycerine":1260/1000,
"Hexane":659/1000,
"Honey":1417/1000,
"Kerosene":815/1000,
"Methanol":787/1000,
"n_octane":692/1000,
"Olive_Oil":910/1000,
"Oil_engine":885/1000,
"Oil_light":910/1000,
"Pentane":626/1000,
"Propane":510/1000,
"R_twelve":1310/1000,
"R_twentyTwo":1190/1000,
"R_OneHundredThirtyFour_a":1206/1000,
"Water":997/1000
}
这是“主”模块:
import Fluid
for element in Fluid.fluiddensitydict():
print(element)
FluidAnswer = input("\nWhich of these fluids would you like: ")
density = Fluid.fluiddensitydict.get(str(FluidAnswer))
for element in Fluid.fluiddensitydict():
if element == FluidAnswer:
print("your chosen fluid is ",element, "and it has the density
:",density)
当我运行文件时,我得到消息:我得到错误: for Fluid.fluiddensitydict()中的元素:TypeError:'dict'对象不可调用
答案 0 :(得分:0)
fluiddensitydict
已被定义为字典,但是您正在作为函数进行调用。您可以遍历键和值,并打印与input()
值具有相同键的字典值:
import Fluid
FluidAnswer = input("\nWhich of these fluids would you like: ")
for element, density in Fluid.fluiddensitydict.iteritems():
if element == FluidAnswer:
print("your chosen fluid is ",element, "and it has the density :",density)