[Mesa-dev] [PATCH 14/26] python: Better get character ordinals

Eric Engestrom eric.engestrom at intel.com
Thu Jul 5 15:56:09 UTC 2018


On Thursday, 2018-07-05 15:17:45 +0200, Mathieu Bridon wrote:
> In Python 2, iterating over a byte-string yields single-byte strings,
> and we can pass them to ord() to get the corresponding integer.
> 
> In Python 3, iterating over a byte-string directly yields those
> integers.
> 
> Transforming the byte string into a bytearray gives us a list of the
> integers corresponding to each byte in the string, removing the need to
> call ord().
> 
> This makes the script compatible with both Python 2 and 3.
> 
> Signed-off-by: Mathieu Bridon <bochecha at daitauha.fr>

Reviewed-by: Eric Engestrom <eric.engestrom at intel.com>

> ---
>  src/intel/genxml/gen_zipped_file.py | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/intel/genxml/gen_zipped_file.py b/src/intel/genxml/gen_zipped_file.py
> index 6d8daf4d69..616409183f 100644
> --- a/src/intel/genxml/gen_zipped_file.py
> +++ b/src/intel/genxml/gen_zipped_file.py
> @@ -62,8 +62,8 @@ def main():
>      print("")
>      print("static const uint8_t compress_genxmls[] = {")
>      print("   ", end='')
> -    for i, c in enumerate(compressed_data, start=1):
> -        print("0x%.2x, " % ord(c), end='\n   ' if not i % 12 else '')
> +    for i, c in enumerate(bytearray(compressed_data), start=1):
> +        print("0x%.2x, " % c, end='\n   ' if not i % 12 else '')
>      print('\n};')
>  
>  
> -- 
> 2.17.1
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list