如何将python long转换为c unsigned int?

2024-04-25 23:59:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从python调用thrift IDL。一个变量的thrift数据类型是I32。 我需要发送介于0和2^32-1之间的值。对于介于2^31和2^32-1之间的值,python将其转换为long。所以,我得到了一个错误,对这些值说'integer超出'I'format code'的范围。我试着转换成ctypes.c\u uint32。它不起作用。 我怎样才能解决这个问题?在


Tags: format错误codeintegerctypesthriftlongidl
1条回答
网友
1楼 · 发布于 2024-04-25 23:59:25

这不是Python的问题,这是您的一个误解,什么数字适合i32字段。在

来自Thrift: The Missing Guide

Note that Thrift does not support unsigned integers because they have no direct translation to native (primitive) types in many of Thrift’s target languages.

Thrift Types documentation

Note the absence of unsigned integer types. This is due to the fact that there are no native unsigned integer types in many programming languages.

强调我的。在

如果要在cd2上使用一个^-31}的值,就不要使用^-31}来代替^-1}的值。在

相关问题 更多 >