I am new to Python. The following code is causing an error when it attempts to append values to an array. What am I doing wrong?
import re
from array import array
freq_pattern = re.compile("Frequency of Incident[\(\)A-Za-z\s]*\.*\s*([\.0-9]*)")
col_pattern = re.compile("([-\.0-9]+)\s+([-\.0-9]+)\s+([-\.0-9]+)\s+([-\.0-9]+)\s+([-\.0-9]+)")
e_rcs = array('f')
f = open('example.4.out', 'r')
for line in f:
print line,
result = freq_pattern.search(line)
if result:
freq = float(result.group(1))
cols = col_pattern.search(line)
if cols:
e_rcs.append = float(cols.group(2))
f.close()
Error
Traceback (most recent call last):
File "D:\workspace\CATS Parser\cats-post.py", line 31, in e_rcs.append = float(cols.group(2)) AttributeError: 'list' object attribute 'append' is read-only attributes (assign to .append)