Hi,
I'm working with an xml file in python.here is the coed that i have:
import sys
from xml.dom.minidom import parse
# Load XML into tree structure
tree = parse(sys.stdin)
#Find all VECTOR_AVERAGE nodes
va_list = tree.getElementsByTagName('SIMULATION')[0].getElementsByTagName('AVERAGES')[0].getElementsByTagName('VECTOR_AVERAGE')
#Find the 'Density Correlations' node in the list of VECTOR_AVERAGEs
for va in va_list:
if va.attributes.getNamedItem('name').nodeValue == 'Density Correlations':
density_correlations = va
break
#Get a list of all the SCALAR_AVERAGES
sa_list = density_correlations.getElementsByTagName('SCALAR_AVERAGE')
#Initialize lists for holding the data
indexvalue_list = []
mean_list = []
error_list = []
variance_list = []
autocorr_list = []
newerror_list = []
#Iterate over all SCALAR_AVERAGEs and put their values into the lists
#above.
for sa in sa_list:
x = sa.attributes.getNamedItem('indexvalue').nodeValue
tuples = [eval(item) for item in x.split("--")]
if tuples[0] == tuples[1]:
indexvalue_list.append(tuples[0])
#indexvalue_list.append(sa.attributes.getNamedItem('indexvalue').nodeValue)
mean_list.append(float(sa.getElementsByTagName('MEAN')[0].childNodes[0].data))
error_list.append(float(sa.getElementsByTagName('ERROR')[0].childNodes[0].data))
variance_list.append(float(sa.getElementsByTagName('VARIANCE')[0].childNodes[0].data))
autocorr_list.append(float(sa.getElementsByTagName('AUTOCORR')[0].childNodes[0].data))
newerror_list = error_list * error_list
print "#indexvalue MEAN\tERROR\tVARIANCE\tAUTOCORR\tNewError"
for i in range(len(mean_list)):
print "%s\t%g\t%g\t%g\t%g\t%g" % (indexvalue_list[i],mean_list[i],error_list[i],variance_list[i],autocorr_list[i],newerror_list[i])
I'm extracting data form the file and need to do some math process on them. but they apparently are not int. Cause i'm getting the following error:
newerror_list = error_list * error_list
TypeError: can't multiply sequence by non-int
Any suggestion how i can solve this problem?