Using ctypes with jython

后端 未结 4 1577
梦如初夏
梦如初夏 2021-01-19 12:27

I have a trouble with using ctypes lib in my python script. Here is my code (found on the Internet):

if __name__ == \"__main__\":
    from ctypes import *
           


        
4条回答
  •  执念已碎
    2021-01-19 12:40

    ctypes in Jython experimental and not complete.

    From the jython-users mailing list in a thread titled "ctypes in Jython" Jim Baker (a Jython committer) wrote on November 17, 2010:

    There's some experimental support for ctypes in 2.5.2 [the current version], but it's really more of a placeholder at this point.

    He then suggests these work arounds:

    I do recommend JNA if you can modify your ctypes code. JNA is pretty close to ctypes - JNA's API apparently was significantly influenced by ctypes! JNA also seems to work well with Jython.

    The other option is to use something like execnet. For execnet specifically: it allows you to pair Jython with CPython, and it does seem to work well. But its GPL license makes it a non starter for many people. There are other choices out there too.

    Further on in the same thread we have this confirming assessment:

    I tried the ctypes module in 2.5.2rc2 recently, and found that: 1) There's no ctypes.util.find_library yet 2) ctypes.Structure doesn't support non-scalar types yet

    So I agree with the "more of a placeholder" assessment. Still, it's exciting to see it getting started.

提交回复
热议问题