Writing Log CSV (Efficiently)

Robert Rawlins - Think Blue robert.rawlins at thinkbluemedia.co.uk
Mon Apr 16 10:57:10 EDT 2007


Thanks for that Tim,

I could use a little more help with this CSV stuff this afternoon and I
can't get it to write the output I want for the life of me. I'm trying to
write a method for my logging class that receives a string as an argument,
and then writes a row to the CSV with the string and a date/time stamp.

	''' Add Application Log Entry '''
	def addApp(self, event):
		writer = csv.writer(open("some.csv", "a"))
		writer.writerow(event)

Now if I do something like this; addApp('Application Started') then it
writes to the CSV file somthing like.

A,p,p,l,i,c,a,t,i,o,n, ,S,t,a,r,t,e,d

Which isn't much use to me :-D any ideas how I can get something like this:

2007-01-01,13:00:00,Application Started

Thanks,

Rob
-----Original Message-----
From: python-list-bounces+robert.rawlins=thinkbluemedia.co.uk at python.org
[mailto:python-list-bounces+robert.rawlins=thinkbluemedia.co.uk at python.org]
On Behalf Of Tim Golden
Sent: 16 April 2007 15:28
Cc: python-list at python.org
Subject: Re: Writing Log CSV (Efficiently)

Robert Rawlins - Think Blue wrote:
> The log at its highest rate of write may be looking at an operation a
> second

I think I can probably type stuff in faster than that if
I try :) You probably don't have a performance issue there.

, I've not got much experience with this kind of thing so 
I'm not sure
> if that's 'a lot' or not, it just seems like it at the moment. It might
not
> get as busy as that, I'm not sure and its difficult to simulate as this
> isn't likely to be a steady flow of traffic, they'll come in big fat lumps
> every now and then.

Sounds like you don't really need to profile that, but if
you did, Python's a great language for knocking together
that kind of test harness; combine the time, random and
csv modules and you've got a "big fat lumps every now and
then" simulation. (At which point I get jumped on by the
serious model types for being so blase with their discipline!)

TJG
-- 
http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list