[Baypiggies] newbie question - automating my reporting tasks

Alden Meneses aldenm at gmail.com
Thu May 17 00:25:16 CEST 2007


Max - Thanks for your reply. The text files are not in csv format and I will
need to figure out how to separate the fields. Space as a separator will not
work as values have spaces in them. The current text file I am looking
at seems to have fields that are at fixed width and the each line I want are
encapsulated in "". The example you showed below will be usefull once I
accomplish the above task.

Chris - Thank you for your reply. The link you provided have some examples
of file and string manipulation which will be a very useful read.

Alden


On 5/16/07, Max Slimmer <max at theslimmers.net> wrote:
>
>  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/52cd48a0/attachment.html 


More information about the Baypiggies mailing list