[Baypiggies] newbie question - automating my reporting tasks
Shannon -jj Behrens
jjinux at gmail.com
Thu May 17 11:54:03 CEST 2007
Don't forget about the "process" module if you need to "shell" out.
If the fields are at fixed positions, read in the entire line and
using string slicing to get them out. By the way, the csv module is
pretty configurable. It can work with tabs, spaces, etc., with all
sorts of quoting rules.
I seem to remember seeing an example in some book of how to automate
Excel using Python and COM. It may have been in "Learning Python" or
the "Python Cookbook". There is a book for Python on Windows. Using
COM in Python is surprisingly easy.
On 5/16/07, Alden Meneses <aldenm at gmail.com> wrote:
> 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.
> 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
> > 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 for row in data)
> > >>> tot
> > 544.65999999999997
> > or you can sort the data by rate:
> > >>> data.sort(key=lambda i:i) # see
> 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
> > 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
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
More information about the Baypiggies