Python从c_double转换为float [英] Python conversion from c_double to float
本文介绍了Python从c_double转换为float的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Python的新手.我想知道将c_double(从ctypes)转换为浮点数的最佳方法是什么.我的代码可以正常工作,但是我想知道是否有Python方式来做到这一点.我目前正在做的是:
I am new to Python. I would like to know what would be the best way to convert a c_double (from ctypes) to a float. My code is working, but I would like to know if there is a pythonic way to do it. What I currently do is:
FloatValue = float( str(d_Val)[9:( len( str(d_Val) ) )-1] )
其中 d_Val
是 c_double(-10.0)
,而我想保留 -10.0
在Windows下使用Python 2.7.
Where d_Val
is c_double(-10.0)
, and I want to keep -10.0
Working with Python 2.7 under windows.
推荐答案
在 c_double
上使用 value
属性.
>>> ctypes.c_double(-10.0).value
-10.0
这篇关于Python从c_double转换为float的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文