Efficient coding advice?

Kelvin Chu kelvin.chu at nospam.uvm.edu
Tue Apr 25 03:32:39 CEST 2000


Dear Python gurus;

I'm writing a bit of code to read the data from AIF files.  Data are
stored as large strings of characters and alternate channels.  In
addition, I want to translate these strings to integers.  So my code
looks like:

data = fp.readframes(nframes)
left = Numeric.zeros(nframes)
right = Numeric.zeros(nframes)
for i in range(0,nframes):
    left[i] = ord(data[i*2])
    right[i] = ord(data[i*2+1])

This seems to take a while, especially since nframes ~ 10^6.  So I
guess my questions are:

1.  Is there an easy way to split a large string so that every-other
    element gets assigned to an array?

2.  Is there an easy way to turn an entire array of characters into
    their ord value?

Thanks very much, I'd appreciate insight you have into this problem.
 

-- 

  kelvin.chu at nospam.uvm.edu			     (802) 656-0064




More information about the Python-list mailing list