Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python conversion from c_double to float

Tags:

python

ctypes

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] )

Where d_Val is c_double(-10.0), and I want to keep -10.0 Working with Python 2.7 under windows.

like image 920
BaldDude Avatar asked Dec 12 '22 15:12

BaldDude


1 Answers

Use the value property on a c_double.

>>> ctypes.c_double(-10.0).value
-10.0
like image 104
tom Avatar answered Dec 31 '22 20:12

tom