array.array

class array.array

Return a new array whose items are restricted by typecode, and initialized from the optional initializer value, which must be a list, string or iterable over elements of the appropriate type.

Arrays represent basic values and behave very much like lists, except the type of objects stored in them is constrained.

Methods:

append() – append a new item to the end of the array buffer_info() – return information giving the current memory info byteswap() – byteswap all the items of the array count() – return number of occurrences of an object extend() – extend array by appending multiple elements from an iterable fromfile() – read items from a file object fromlist() – append items from the list fromstring() – append items from the string index() – return index of first occurrence of an object insert() – insert a new item into the array at a provided position pop() – remove and return item (default last) read() – DEPRECATED, use fromfile() remove() – remove first occurrence of an object reverse() – reverse the order of the items in the array tofile() – write all items to a file object tolist() – return the array converted to an ordinary list tostring() – return the array converted to a string write() – DEPRECATED, use tofile()

Attributes:

typecode – the typecode character used to create the array itemsize – the length in bytes of one array item

Methods

__copy__(array) Return a copy of the array.
__deepcopy__(array) Return a copy of the array.
__format__ default object formatter
__new__((S, ...)
__reduce__ Return state information for pickling.
__reduce_ex__ helper for pickle
__sizeof__(() -> int) Size of the array in memory, in bytes.
__subclasshook__ Abstract classes can override this to customize issubclass().
append(x) Append new value x to the end of the array.
buffer_info() -> (address, length) Return a tuple (address, length) giving the current memory address and the length in items of the buffer used to hold array’s contents The length should be multiplied by the itemsize attribute to calculate the buffer length in bytes.
byteswap() Byteswap all items of the array.
count(x) Return number of occurrences of x in the array.
extend(array or iterable) Append items to the end of the array.
fromfile(f, n) Read n objects from the file object f and append them to the end of the array.
fromlist(list) Append items to array from list.
fromstring(string) Appends items from the string, interpreting it as an array of machine values,as if it had been read from a file using the fromfile() method).
fromunicode(ustr) Extends this array with data from the unicode string ustr.
index(x) Return index of first occurrence of x in the array.
insert(i,x) Insert a new item x into the array before position i.
pop([i]) Return the i-th element and delete it from the array.
read(f, n) Read n objects from the file object f and append them to the end of the array.
remove(x) Remove the first occurrence of x in the array.
reverse() Reverse the order of the items in the array.
tofile(f) Write all items (as machine values) to the file object f.
tolist(() -> list) Convert array to an ordinary list with the same items.
tostring(() -> string) Convert the array to an array of machine values and return the string representation.
tounicode(() -> unicode) Convert the array to a unicode string.
write(f) Write all items (as machine values) to the file object f.

Attributes

itemsize the size, in bytes, of one array item
typecode the typecode character used to create the array