Main Page
Namespaces
Classes
Package Documentation
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
src
RecoLuminosity
LumiDB
python
csvReporter.py
Go to the documentation of this file.
1
import
csv
2
class
csvReporter
(
object
):
3
def
__init__
(self,filename,dialect='excel',delimiter=',',quoting=csv.QUOTE_NONNUMERIC):
4
"""input params:
5
filename : output csv path/name
6
"""
7
self.
__filename
=filename
8
self.
__file
=open(self.
__filename
,
'wb'
)
9
self.
__writer
=csv.writer(self.
__file
)
10
def
writeRow
(self,row):
11
try
:
12
self.__writer.writerow(row)
13
except
csv.Error,e:
14
sys.exit(
'file %s: %s'
%(self.
__filename
,e))
15
def
writeRows
(self,rows):
16
try
:
17
self.__writer.writerows(rows)
18
except
csv.Error,e:
19
sys.exit(
'file %s: %s'
%(self.
__filename
,e))
20
def
close
(self):
21
self.__file.close()
22
23
if
__name__ ==
'__main__'
:
24
filename=
'testwrite.csv'
25
r=
csvReporter
(filename,dialect=
'excel'
,delimiter=
','
)
26
fieldnames=[
't1'
,
't2'
,
't3'
]
27
r.writeRow(fieldnames)
28
data=[1,2,
'a'
]
29
r.writeRow(data)
30
data=[11,22,
'aa'
]
31
r.writeRow(data)
32
#print csv.list_dialects()
33
r.writeRow(data)
34
delivered=[[
'run'
,
'deliveredls'
,
'delivered'
],[1234,23445,123.456],[2348,20,8893.0]]
35
r.writeRows(delivered)
36
r.close()
csvReporter.csvReporter.__filename
__filename
Definition:
csvReporter.py:7
csvReporter.csvReporter.__init__
def __init__
Definition:
csvReporter.py:3
csvReporter.csvReporter
Definition:
csvReporter.py:2
csvReporter.csvReporter.close
def close
Definition:
csvReporter.py:20
csvReporter.csvReporter.__file
__file
Definition:
csvReporter.py:8
dbtoconf.object
list object
Definition:
dbtoconf.py:77
csvReporter.csvReporter.__writer
__writer
Definition:
csvReporter.py:9
csvReporter.csvReporter.writeRows
def writeRows
Definition:
csvReporter.py:15
csvReporter.csvReporter.writeRow
def writeRow
Definition:
csvReporter.py:10
Generated for CMSSW Reference Manual by
1.8.5