3 回答

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超6個(gè)贊
這將做您想要的:
signum = status & 0xff
exitstatus = (status & 0xff00) >> 8

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超6個(gè)贊
要回答您的一般問題,您可以使用位操作
pid, status = os.wait()
exitstatus, signum = status & 0xFF, (status & 0xFF00) >> 8
但是,還有內(nèi)置函數(shù)可用于解釋退出狀態(tài)值:
pid, status = os.wait()
exitstatus, signum = os.WEXITSTATUS( status ), os.WTERMSIG( status )
也可以看看:
os.WCOREDUMP()
os.WIFCONTINUED()
os.WIFSTOPPED()
os.WIFSIGNALED()
os.WIFEXITED()
os.WSTOPSIG()

TA貢獻(xiàn)1963條經(jīng)驗(yàn) 獲得超6個(gè)贊
您可以使用struct模塊將int分解為無符號字節(jié)的字符串:
import struct
i = 3235830701 # 0xC0DEDBAD
s = struct.pack(">L", i) # ">" = Big-endian, "<" = Little-endian
print s # '\xc0\xde\xdb\xad'
print s[0] # '\xc0'
print ord(s[0]) # 192 (which is 0xC0)
如果將其與數(shù)組模塊結(jié)合使用,則可以更方便地執(zhí)行此操作:
import struct
i = 3235830701 # 0xC0DEDBAD
s = struct.pack(">L", i) # ">" = Big-endian, "<" = Little-endian
import array
a = array.array("B") # B: Unsigned bytes
a.fromstring(s)
print a # array('B', [192, 222, 219, 173])
添加回答
舉報(bào)