简体   繁体   English

python-什么是最大字节等效于java Byte.MAX_VALUE

[英]python - what is max byte equivalent to java Byte.MAX_VALUE

Does python have an equivalence to java's Byte.MAX_VALUE representing the max byte? python是否与代表最大字节的java的Byte.MAX_VALUE等效? I had a look at python sys module, I only managed to find sys.maxint . 我看了看python sys模块,我只设法找到sys.maxint Does it have anything like sys.maxbyte ? 是否有类似sys.maxbyte

UPDATE: 更新:

In my case, I am doing a Hbase Rowkey scan, My rowkey looks like rk1_rk2. 就我而言,我正在执行Hbase Rowkey扫描,我的行键看起来像rk1_rk2。 In order to scan all results for rk1 without knowing exact rk2, My java code looks like: 为了在不知道确切rk2的情况下扫描rk1的所有结果,我的Java代码如下所示:

byte[] startRowBytes = "rk1".getBytes(); 
byte[] endRowBytes = ("rk1" + (char) Byte.MAX_VALUE).getBytes(); 

HbaseScanQuery query = new   HbaseScanQuery(tableName, colFamily);
query.setStartRow(startRowBytes).setStopRow(endRowBytes);

I am just trying to work out the python equivalence of Byte.MAX_VALUE part. 我只是想计算出Byte.MAX_VALUE部分的python等效项。

I think you will have to define the value yourself. 我认为您必须自己定义值。 A byte has 2^8 = 256 unique states and so the largest integer it can represent is 255. java's byte type, however, is a signed byte, so half the states are reserved for positives(and 0) and the other half is used for negatives. 字节具有2 ^ 8 = 256个唯一状态,因此它可以表示的最大整数是255。java的字节类型是带符号的字节,因此一半的状态保留为正数(和0),另一半用于否定的。 therefore the the equivalent of java's Byte.MAX_VALUE is 127, and the equivalent of java's Byte.MIN_VALUE is -128 因此,java的Byte.MAX_VALUE的等效项是127,而Java的Byte.MIN_VALUE的等效项是-128

Since python bytes are unsigned, the equivalent of java's Byte.MIN_VALUE would be 128 which is the representation of -128 in 2's compliment notation(the defacto standard for representing signed integers) thanks to Ignacio Vazquez-Abrams for pointing that out. 由于python字节是无符号的,因此感谢Ignacio Vazquez-Abrams指出了这一点,Java的Byte.MIN_VALUE的等效值为128,这是2的恭维表示法(表示带符号整数的实际标准)中的-128的表示形式。

I haven't dealt with python in a while, but i believe what you want is ("rk1"+chr(127)) 我已经有一段时间没有处理python了,但是我相信您想要的是(“ rk1” + chr(127))

Given your update, there is an even better answer: Don't worry about what the max byte value is. 根据您的更新,还有一个更好的答案:不要担心最大字节值是多少。 According to the HBase documentation , the setStartRow and setStopRow methods work just like Python's slicing; 根据HBase文档setStartRowsetStopRow方法的工作方式类似于Python的切片。 namely, the start is inclusive, but the stop is exclusive , meaning your endRowBytes should simply be 'rk2' . 也就是说,开始是包含在内的,但停止是排斥的 ,这意味着endRowBytes应该只是'rk2'

Also, the documentation mentions that you can make the stop row inclusive by adding a zero byte, so another alternative is 'rk1' + chr(0) (or 'rk1\\0' or 'rk1\\x00' , whichever is clearest to you). 此外,文档还提到您可以通过添加字节来使停止行包含在内,因此另一种替代方法是'rk1' + chr(0) (或'rk1\\0''rk1\\x00' ,以您最清楚的为准) )。 In fact, the example used to explain HBase scans in the linked documentation illustrates exactly your use case. 实际上,链接文档中用于解释HBase扫描的示例完全说明了您的用例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM