简体   繁体   中英

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? I had a look at python sys module, I only managed to find sys.maxint . Does it have anything like sys.maxbyte ?

UPDATE:

In my case, I am doing a Hbase Rowkey scan, My rowkey looks like rk1_rk2. In order to scan all results for rk1 without knowing exact rk2, My java code looks like:

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.

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. therefore the the equivalent of java's Byte.MAX_VALUE is 127, and the equivalent of java's Byte.MIN_VALUE is -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.

I haven't dealt with python in a while, but i believe what you want is ("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; namely, the start is inclusive, but the stop is exclusive , meaning your endRowBytes should simply be '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). In fact, the example used to explain HBase scans in the linked documentation illustrates exactly your use case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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