Go to the documentation of this file.00001 import csv
00002 def is_intstr(s):
00003 try:
00004 int(s)
00005 return True
00006 except ValueError:
00007 return False
00008 class csvSelectionParser(object):
00009 def __init__(self,filename):
00010 self.__result={}
00011 self.__strresult={}
00012 self.__filename=filename
00013 csvReader=csv.reader(open(filename),delimiter=',')
00014 for row in csvReader:
00015 field0=str(row[0]).strip()
00016 try:
00017 field1=str(row[1]).strip()
00018 except Exception,e:
00019 field1='1'
00020 if not is_intstr(field0) or not is_intstr(field1):
00021 continue
00022 runnumber=int(field0)
00023 lsnumber=int(field1)
00024 if self.__result.has_key(runnumber):
00025 self.__result[runnumber].append(lsnumber)
00026 else:
00027 self.__result[runnumber]=[lsnumber]
00028 for k,lsvalues in self.__result.items():
00029 lsvalues.sort()
00030 self.__strresult[k]=[str(x) for x in lsvalues]
00031 def runs(self):
00032 return self.__result.keys()
00033 def runsandls(self):
00034 '''return {run:lslist}
00035 '''
00036 return self.__result
00037 def runsandlsStr(self):
00038 '''return {'run':lslist}
00039 '''
00040 return self.__strresult
00041 def numruns(self):
00042 return len(self.__result.keys())
00043 def numls(self,run):
00044 return len(self.__result[run])
00045
00046 if __name__ == '__main__':
00047 result={}
00048
00049 filename='../test/newruns.csv'
00050 s=csvSelectionParser(filename)
00051 print 'runs : ',s.runs()
00052 print 'full result : ',s.runsandls()
00053 print 'str result : ',s.runsandlsStr()
00054 print 'num runs : ',s.numruns()
00055
00056