[Baypiggies] newbie question - automating my reporting tasks

Max Slimmer max at theslimmers.net
Wed May 16 21:43:56 CEST 2007


You indicated you receive text files, if they are comma delimited you can
parse them with the csv library and thus read them into python lists of
lists
onece you have your data in a list of lists you could simply operate on it
there or you could create objects from each list element leaving you with a
list of objects exch representing one row.
 
say you keep it simple and you have incoming data consisting of name, rate,
amt. 
>>> data = [['name1',12.5, 123.66],['name2',5.6,421]]
>>> data
[['name1', 12.5, 123.66], ['name2', 5.5999999999999996, 421]]
you can sum all the amt's with 
>>> tot = sum(row[2] for row in data)
>>> tot
544.65999999999997
or you can sort the data by rate:
>>> data.sort(key=lambda i:i[1])   # see
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/305304 for
interesting things to do with sort
>>> data
[['name2', 5.5999999999999996, 421], ['name1', 12.5, 123.66]]
 
play with the interactive interpreter 
 
max
 


  _____  

From: baypiggies-bounces at python.org [mailto:baypiggies-bounces at python.org]
On Behalf Of Alden Meneses
Sent: Wednesday, May 16, 2007 10:45 AM
To: baypiggies at python.org
Subject: [Baypiggies] newbie question - automating my reporting tasks


Hello all,
 
It does seem that Python is easier to lean than PERL. and I like the
interpreter.
 
I have some text files that I download from an AS400 and format with Excel.
Basically I convert the text to columns then sort and subtotal. The results
are then emailed to various people and also used in other reports. Haven't
really thought out how to automate this whole process but wanted to start
with a project to learn python and go from there. 
 
I have skimmed throught the python tutorial and now getting into python in a
nutshell, 2nd edition and would welcome any thoughts or suggestions in
getting my project off the ground. I've taken programming courses in college
- C, C++, PERL, FORTRAN, PASCAL, UNIX shell scripting and its been awhile
since I had to rely on it. 
 
Thanks in advance,
Alden

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/baypiggies/attachments/20070516/a74adcc5/attachment-0001.html 


More information about the Baypiggies mailing list