Repeatedly appending to a large list (Python 2.6.6)

前端 未结 5 699
小蘑菇
小蘑菇 2020-12-29 05:30

I have a project where I am reading in ASCII values from a microcontroller through a serial port (looks like this : AA FF BA 11 43 CF etc) The input is coming in quickly (38

5条回答
  •  天命终不由人
    2020-12-29 06:10

    It might be faster to use numpy if you know how long the array is going to be and you can convert your hex codes to ints:

    import numpy
    a = numpy.zeros(3000000, numpy.int32)
    for i in range(3000000):
       a[i] = int(scanHexFromSerial(),16)
    

    This will leave you with an array of integers (which you could convert back to hex with hex()), but depending on your application maybe that will work just as well for you.

提交回复
热议问题