Ctypes Python. How do you use arithmetic surgery?
-
For example, the code is:
from ctypes import c_longlong as ll k = ll(10**17-1) k-=1
This code doesn't work.
from ctypes import c_longlong as ll k = ll(10**17-1) k-=ll(1)
So is it. How do you put the arithmetic in the "shit" type? How to give class a method add Or are there other ways?
-
In such situations, the operation should be used
dir
:>>> dir(k) ['__bool__', '__class__', '__ctype_be__', '__ctype_le__', '__ctypes_from_outparam__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_b_base_', '_b_needsfree_', '_objects', '_type_', 'value']
And obviously value is the field that needs to be
>>> k.value 99999999999999999 >>> k.value -= 1 >>> k c_longlong(99999999999999998)
The other way is...
help(k)
♪ Well, of course, you can just read the documentation totypes.