Ruby to Python syntax syntax

I am trying to convert Ruby code to my Python code. Initially, the developer is no longer with us, and I do not know Ruby. Most of its code is quite simple, but some of the following syntaxes disable me.

Example:

                myTable = ''
                myTable << [ 0, 1, 0, 0, 0, 300].pack('vvvvvv')
                myTable [40, 4] = [41310005 - 5].pack('V')

1) Do I correctly assume that after the second line myTable will contain an array of 6 values ​​specified in []? And what .pack()does Python look like struct.pack?

2) After the third line, the value on the right will be stored at position 40 in the array and should it be 4 bytes long? Is -5 in [] just that he has fun or has some special meaning?

+3
source share
3 answers

, , struct.pack. myTable - . Array#pack() ( struct.pack), String#<< . 4 40 [41310000].pack('V').

+3

Array#pack. . v - "Short, little-endian byte order", v - "Long, little-endian byte order".

<< String. , myTable [0, 1, 0, 0, 0, 300].pack('vvvvvv').

String#[m,n]= m m+n.

+2

, myTable - ( ). < ( ) append, . pack , "Short, little-endian byte order". 6 , ASCII , .

, ", - ". 40 4 .

. , myTable - , .

+1

Source: https://habr.com/ru/post/1765685/


All Articles