2012-04-26 47 views
0

我想構建一個Python模塊的包裝,將其嵌入到我的java代碼中。Jython,subprocess和msvcrt ...有可能嗎?

看起來像該模塊使用了許多的技巧,比如子,穿線等

(實際上它本身就是控制一個C程序提供AS-IS,僅作爲二進制模塊,我試圖避免overcost重新編碼已經提供了這個Python包裝的內在邏輯和其他工具)

順便說一下,當實例化了我自己從Java包裝我得到:

------------------ 
Exception in thread "MainThread" Traceback (most recent call last): 
    File "<string>", line 1, in <module> 
    File "__pyclasspath__/mywrapper.py", line 303, in <module> 
    File "C:\jython2.5.2\Lib\subprocess.py", line 375, in <module> 
    import msvcrt 
ImportError: No module named msvcrt 

,如果我看在我的硬盤,還有沒有msvscrt.py它在哪裏不想生活?

我正在發動我的Jython有:

PythonInterpreter interpreter = new PythonInterpreter(null, new PySystemState()); 

    PySystemState sys = Py.getSystemState(); 
    sys.path.append(new PyString("C:/jython2.5.2/Lib")); 
    sys.platform = new PyString("win32"); // this is a trick for the wrapper to not fail on a inner plateform test detection with java1.7.0_03 

回答

1

msvcrt不可用Jython中。在Windows上的CPython中,msvcrt是一個編譯到Python解釋器中的內置模塊(可以用sys.builtin_module_names來檢查)。沒有msvcrt.py文件。

爲什麼你需要「使用java1.7.0_03進行內平板測試檢測時不會失敗的包裝技巧」,我不能說。但將sys.platform設置爲win32會使Jython在使用subprocess時嘗試導入msvcrt,這不起作用。

+0

謝謝!我不知道你如何能夠檢查,但適應我的sys.platform值依賴的部分,而不改變實際值'win32'做到了!順便說一句,我很遠比猜測它被鏈接!在我的問題中,我甚至不會在這裏寫下它... – user1340802 2012-05-04 09:27:32