[SciPy-user] reload / auto gui_thread / file striding

Francis Burton F.L.Burton at udcf.gla.ac.uk
Tue May 7 09:07:44 EDT 2002


Now that I have SciPy working with python (under NT not 95),
and am thoroughly enjoying the experience of strolling up the
gentle learning curve, I have a few questions which seasoned
users might be able to help me with. (I hope it's not considered
poor etiquette to ask multiple questions in a single post!) 

1) I have a module which I want to edit and test incrementally
   by invoking functions interactively in IDLE after I have
   typed "from mymodule import *". Do I really have to quit and
   restart IDLE after every change? One of the books mentions
   reload, but this just raises a NameError: name 'mymodule' is
   not defined. What is the correct way to do edit-run cycles?

2) Is there any way I can get IDLE (or plain python) to execute
   "import gui_thread/from scipy import plt/from scipy import *"
   automatically when I start it up? Given the fact I have to
   quit and restart repeatedly, it is a bit of a pain to have
   to retype these statements. (I prefer to use IDLE because the
   syntax coloring and function arg hints are really helpful.)

3) I'm extracting 16 bit integers from a binary data file which
   consists of consecutive frames of 256 digitized channels
   (which follow a fixed sized header). I want to process each
   channel in turn. This means repeatedly seeking forward,
   reading a integer, and appending the value to an array.
   Then I have to write the processed values back to the file.
   The way I am doing it is as follows:

def ReadChannel(chan):
    trace = array('d')
    word = array('H')
    for i in range(nframes):
        offset = ( chan + 256*i + 154 ) * 2
        f.seek(offset)
        word.fromfile(f, 1)
        trace.append(float(word[0]))
        word.pop()
    f.close()
    return trace

def WriteChannel(trace, chan):
    word = array('H', [0])
    f = open(filename, 'r+b')
    for i in range(nframes):
        offset = ( chan + 256*i + 154 ) * 2
        f.seek(offset)
        word[0] = trace[i]   # truncation ok
        word.tofile(f)
    f.close()

   The code for writing is quite intuitive, whereas that for
   reading is not - because it involves an additional call
   to 'pop'. It seems strangely asymmetric to me. But is this
   a good way to handle this situation?

Thanks very much in advance!

Francis




More information about the SciPy-User mailing list