8.7. array


() (array) (sequence) :

C Python ()
'b' signed char int 1  
'B' unsigned char int 1  
'u' Py_UNICODE Unicode(unicode) 2 (1)
'h' signed short int 2  
'H' unsigned short int 2  
'i' signed int int 2  
'I' unsigned int int 2  
'l' signed long int 4  
'L' unsigned long int 4  
'q' signed long long int 8 (2)
'Q' unsigned long long int 8 (2)
'f' 4  
'd' double 8  

:

  1. 'u' Python Unicode (Py_UNICODE wchar_t) 16bit 32bit

    'u' Py_UNICODE API

    3.3 4.0 .

  2. 'q' 'Q' Python C C long long Windows __int64

    3.3 .

(C) itemsize

:

class array.array(typecode[, initializer])

typecode initializer bytes-like object

initializer fromlist() frombytes() fromunicode() () initializer extend()

array.typecodes

TypeError bytes-like objects

:

array.typecode

array.itemsize

1

array.append(x)

x

array.buffer_info()

(address, length) array.buffer_info()[1] * array.itemsize ioctl() () I/O

C C++ (buffer_info() ) (buffer Protocol)

array.byteswap()

() 124 8 RuntimeError

array.count(x)

x

array.extend(iterable)

iterable iterable TypeError iterable

array.frombytes(s)

( fromfile() )

array.fromfile(f, n)

f () n n EOFError f read()

array.fromlist(list)

for x in list: a.append(x)

array.fromstring()

frombytes()

array.fromunicode(s)

Unicode 'u' ValueError Unicode array.frombytes(unicodestring.encode(enc))

array.index(x)

x i

array.insert(i, x)

i x i

array.pop([i])

i -1

array.remove(x)

x

array.reverse()

array.tobytes()

array array bytes (tofile() )

array.tofile(f)

() file object f

array.tolist()

array.tostring()

tobytes()

array.tounicode()

Unicode 'u' ValueError Unicode array.tobytes().decode(enc)

array(typecode, initializer) initializer typecode 'u' array from array import array eval() :

array('l')
array('u', 'hello \u2641')
array('l', [1, 2, 3, 4, 5])
array('d', [1.0, 2.0, 3.14])

struct
xdrlib
(External Data Representation, XDR)
Numerical Python
Numeric Python (NumPy) Numerical Python http://www.numpy.org/