Which is more efficient for buffer manipulation: python strings or array ()

I am creating a routine that processes disk buffers for judicial purposes. Am I better off using python strings or an array () type? My first thought was to use strings, but I am trying to nullify unicode problems, so maybe array ('c') is better?

+3
source share
2 answers

Write the code using the most natural (lines), find out if it is too slow, and then improve it.

Arrays can be used as a replacement for replacement strin most cases, if you restrict yourself to access the index and section. Both are fixed. Both should have approximately the same memory requirements. Arrays are mutable if you need to change buffers. Arrays can be read directly from files, so reading does not require a speed limit.

I do not understand how you avoid Unicode problems using arrays. str- it's just an array of bytes and knows nothing about the encoding of a string.

I assume that the disk buffers you mentioned can be quite large, so you might consider using mmap:

, , , . , , . mmap , ; , re . theyre mutable, , obj [index] = 'a' , : obj [i1: i2] = '...'. , , () .

+9

( , , "" ), array, , , str . Python 2.6 , bytearray - .

array ( , , ), Python bytearray. Unicode ( Python 2, Python 3, bytearray! -).

+6
source

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


All Articles