[英]having problems with importing variables from other files in the same folder.
Tried to import i Dictionary from another file in the same folder. 试图从同一文件夹中的另一个文件导入i Dictionary。
this is the "fluid" module: 这是“流体”模块:
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
}
Here is the "main" module: 这是“主要”模块:
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)
when i run the file i get the message:i get the error : for element in Fluid.fluiddensitydict(): TypeError: 'dict' object is not callable 当我运行文件时,我得到消息:我得到错误:对于Fluid.fluiddensitydict()中的元素:TypeError:'dict'对象不可调用
fluiddensitydict
is already defined as a dictionary however you are calling as a function. fluiddensitydict
已被定义为字典,但是您正在作为函数进行调用。 You can iterate through both Keys and values and print the value of your dictionary which has the same key as your input()
value: like this: 您可以遍历键和值,并打印与
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.