Vizard 7 » Tutorials & Examples » Example scripts » File I/O » Read
7.7

read

\examples\file_io\read.py

Reads data from a text file and parses into arrays.

"""
Read data from file 'response.txt' and parse into arrays.
You should first run 'write' demo to create this file.
"""
import viz

viz.go()

import vizinfo
vizinfo.InfoPanel()

time    =   []                     # defines empty array
key     =   []                     # defines empty array

file = open('response.txt', 'r')    # opens file 'stimulus.txt'

for line in file:                  # this loop works it's way
                                    # through file, line by line.
    s = line.split()               # each line is split in it's
                                    # components.

    time.append(float(s[0]))        # the first component is
                                    # assigned to time,
    key.append(s[1])                # the second to type

file.close()                       # the stimulus file is closed

print(time                         )# shows the resulting arrays
print(key                          )# in interactive window