python输出数据类型_Python ctypes:获取变量类型和值问题

importctypes

iphreeqc=ctypes.CDLL("libiphreeqc.0.dylib",ctypes.RTLD_GLOBAL)# C structures from var.hclassVAR_TYPE(ctypes.Structure):_fields_=[("TT_EMPTY",ctypes.c_int),("TT_ERROR",ctypes.c_int),("TT_LONG",ctypes.c_int),("TT_DOUBLE",ctypes.c_int),("TT_STRING",ctypes.c_int)](TT_EMPTY,TT_ERROR,TT_LONG,TT_DOUBLE,TT_STRING)=map(ctypes.c_int,xrange(5))classVRESULT(ctypes.Structure):_fields_=[("VR_OK",ctypes.c_int),("VR_OUTOFMEMORY",ctypes.c_int),("VR_BADVARTYPE",ctypes.c_int),("VR_INVALIDARG",ctypes.c_int),("VR_INVALIDROW",ctypes.c_int),("VR_INVALIDCOL",ctypes.c_int)](VR_OK,VR_OUTOFMEMORY,VR_BADVARTYPE,VR_INVALIDARG,VR_INVALIDROW,VR_INVALIDCOL)=map(ctypes.c_int,xrange(0,-6,-1))class_U(ctypes.Union):_fields_=[("lVal",ctypes.c_long),("dVal",ctypes.c_double),("sVal",ctypes.c_char),("vresult",VRESULT)]classVAR(ctypes.Structure):_anonymous_=("pvar",)_fields_=[("pvar",_U),("type",VAR_TYPE)]# Run modelId=iphreeqc.CreateIPhreeqc()dbloade=iphreeqc.LoadDatabase(Id,"phreeqc.dat")estring=iphreeqc.OutputErrorString(Id)# Model inputiphreeqc.AccumulateLine(Id,"TITLE Example 2.--Temperature dependence of solubility")iphreeqc.AccumulateLine(Id," of gypsum and anhydrite ")iphreeqc.AccumulateLine(Id,"SOLUTION 1 Pure water ")iphreeqc.AccumulateLine(Id," pH 7.0 ")iphreeqc.AccumulateLine(Id," temp 25.0 ")iphreeqc.AccumulateLine(Id,"EQUILIBRIUM_PHASES 1 ")iphreeqc.AccumulateLine(Id," Gypsum 0.0 1.0 ")iphreeqc.AccumulateLine(Id," Anhydrite 0.0 1.0 ")iphreeqc.AccumulateLine(Id,"REACTION_TEMPERATURE 1 ")iphreeqc.AccumulateLine(Id," 25.0 75.0 in 50 steps ")iphreeqc.AccumulateLine(Id,"SELECTED_OUTPUT ")iphreeqc.AccumulateLine(Id," -file ex2.sel ")iphreeqc.AccumulateLine(Id," -user_punch true ")iphreeqc.AccumulateLine(Id," -reset false ")iphreeqc.AccumulateLine(Id," -simulation false ")iphreeqc.AccumulateLine(Id," -selected_out true ")iphreeqc.AccumulateLine(Id," USER_PUNCH ")iphreeqc.AccumulateLine(Id," -start ")iphreeqc.AccumulateLine(Id," 10 punch - LA('H+') ")iphreeqc.AccumulateLine(Id," -end ")iphreeqc.AccumulateLine(Id,"END ")# run modelrunout=iphreeqc.RunAccumulated(Id)estring2=iphreeqc.OutputErrorString(Id)a=iphreeqc.GetSelectedOutputRowCount(Id)b=iphreeqc.GetSelectedOutputColumnCount(Id)printaprintb# this works, gives correct number of rows and columnsvart=VAR()iphreeqc.VarInit(ctypes.byref(vart))c=iphreeqc.GetSelectedOutputValue(Id,43,0,ctypes.byref(vart))#tries to extract value from row 43, column 1printc# c is here VRESULT. this works properly giving the right error number (0 to -6). Gives 0 in this case which is VR_OK

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值