我正在启动从python到jython的迁移过程。以前有人这么做过吗?
有什么问题?我应该先在JythonIDE内部构建然后部署还是什么?

最佳答案

请记住,在jython中,在Java下运行时,无论您在哪个平台上,一切都是“Big-Endian”,而在PC/Linux/Mac(x86)平台上,python是Little-Endian。确保在使用struct.pack和struct.unpack时使用适当的前缀
不带前缀
写入数据(enessw.py)

import struct
f = file('tmp.dat', 'wb') # binary
f.write(struct.pack('IIII', 1,2,3,4)) # default endianess

读取数据(enessr.py)
import struct
f = file('tmp.dat', 'rb')
data = f.read()
ints = struct.unpack('IIII', data) # default endianess
print repr(ints)

结果
用python编写,用jython读取
C:\Documents and Settings\mat99856\My Documents\tmp>python enessw.py

C:\Documents and Settings\mat99856\My Documents\tmp>python enessr.py
(1, 2, 3, 4)

C:\Documents and Settings\mat99856\My Documents\tmp>jython enessr.py
(16777216L, 33554432L, 50331648L, 67108864L)

用jython写用python读
C:\Documents and Settings\mat99856\My Documents\tmp>jython enessw.py

C:\Documents and Settings\mat99856\My Documents\tmp>jython enessr.py
(1L, 2L, 3L, 4L)

C:\Documents and Settings\mat99856\My Documents\tmp>python enessr.py
(16777216, 33554432, 50331648, 67108864)

修复
在pack and unpack的格式字符串中使用以“
C:\Documents and Settings\mat99856\My Documents\tmp>python enessw.py

C:\Documents and Settings\mat99856\My Documents\tmp>python enessr.py
(1, 2, 3, 4)

C:\Documents and Settings\mat99856\My Documents\tmp>jython enessr.py
(1L, 2L, 3L, 4L)

C:\Documents and Settings\mat99856\My Documents\tmp>jython enessw.py

C:\Documents and Settings\mat99856\My Documents\tmp>jython enessr.py
(1L, 2L, 3L, 4L)

C:\Documents and Settings\mat99856\My Documents\tmp>python enessw.py

C:\Documents and Settings\mat99856\My Documents\tmp>python enessr.py
(1, 2, 3, 4)

C:\Documents and Settings\mat99856\My Documents\tmp>jython enessr.py
(1L, 2L, 3L, 4L)

工具书类
struct.pack

10-06 05:05
查看更多