3 回答

TA贡献1829条经验 获得超6个赞
要回答您的一般问题,您可以使用位操作
pid, status = os.wait()
exitstatus, signum = status & 0xFF, (status & 0xFF00) >> 8
但是,还有内置函数可用于解释退出状态值:
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贡献1963条经验 获得超6个赞
您可以使用struct模块将int分解为无符号字节的字符串:
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)
如果将其与数组模块结合使用,则可以更方便地执行此操作:
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])
添加回答
举报