<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.3059" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=484450923-16052007><FONT face=Arial
color=#0000ff size=2>def getData():</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=484450923-16052007> <FONT
face=Arial color=#0000ff size=2>f = open('datafile.txt')</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=484450923-16052007> <FONT
face=Arial color=#0000ff size=2> itmList = []</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN
class=484450923-16052007> <FONT face=Arial
color=#0000ff size=2>for line in f:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN
class=484450923-16052007> <FONT
face=Arial color=#0000ff size=2>itm = MYCLASS()</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN
class=484450923-16052007> <FONT
face=Arial color=#0000ff size=2>itm.name = line[0:20].strip() # get name
from 1st 20 chars in line and strip any trailing (in this case also leading vs
rstrip()) whitespace</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN
class=484450923-16052007> <FONT
face=Arial color=#0000ff size=2>itm.rate =
float(line[20:28] </FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN
class=484450923-16052007> <FONT
face=Arial color=#0000ff size=2>itmList.append(itm)</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=484450923-16052007> <FONT
face=Arial color=#0000ff size=2>f.close()</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=484450923-16052007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=484450923-16052007><FONT face=Arial
color=#0000ff size=2># now you can iterate over itmList you could also have just
made a list of lists instead of a list of MYCLASS objects</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=484450923-16052007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=484450923-16052007><FONT face=Arial
color=#0000ff size=2>class MYCLASS(object):</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=484450923-16052007> <FONT
face=Arial color=#0000ff size=2>pass # this
creates an empty object and you can dynamically add members to
it.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=484450923-16052007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=484450923-16052007><FONT face=Arial
color=#0000ff size=2>max</FONT></SPAN></DIV><BR>
<BLOCKQUOTE
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Alden Meneses [mailto:aldenm@gmail.com]
<BR><B>Sent:</B> Wednesday, May 16, 2007 3:25 PM<BR><B>To:</B> Max
Slimmer<BR><B>Cc:</B> baypiggies@python.org<BR><B>Subject:</B> Re:
[Baypiggies] newbie question - automating my reporting
tasks<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV>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. </DIV>
<DIV> </DIV>
<DIV>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.</DIV>
<DIV> </DIV>
<DIV>Alden<BR><BR> </DIV>
<DIV><SPAN class=gmail_quote>On 5/16/07, <B class=gmail_sendername>Max
Slimmer</B> <<A onclick="return top.js.OpenExtLink(window,event,this)"
href="mailto:max@theslimmers.net" target=_blank>max@theslimmers.net</A> >
wrote:</SPAN>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2>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
</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2>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. </FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2>say you
keep it simple and you have incoming data consisting of name, rate, amt.
</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff
size=2>>>> data = [['name1',12.5,
123.66],['name2',5.6,421]]</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff
size=2>>>> data</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff
size=2>[['name1', 12.5, 123.66], ['name2', 5.5999999999999996,
421]]</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2>you can
sum all the amt's with </FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff
size=2>>>> tot = sum(row[2] for row in data)</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff
size=2>>>> tot<BR>544.65999999999997</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2>or you
can sort the data by rate:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff
size=2>>>> data.sort(key=lambda i:i[1]) # see <A
onclick="return top.js.OpenExtLink(window,event,this)"
href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/305304"
target=_blank>http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/305304</A> for
interesting things to do with sort</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff
size=2>>>> data<BR>[['name2', 5.5999999999999996, 421], ['name1',
12.5, 123.66]]</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2>play
with the interactive interpreter </FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff
size=2>max</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV><BR>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV lang=en-us dir=ltr align=left>
<HR>
<FONT face=Tahoma size=2><B>From:</B> <A
onclick="return top.js.OpenExtLink(window,event,this)"
href="mailto:baypiggies-bounces@python.org"
target=_blank>baypiggies-bounces@python.org</A> [mailto:<A
onclick="return top.js.OpenExtLink(window,event,this)"
href="mailto:baypiggies-bounces@python.org" target=_blank>
baypiggies-bounces@python.org</A>] <B>On Behalf Of </B>Alden
Meneses<BR><B>Sent:</B> Wednesday, May 16, 2007 10:45 AM<BR><B>To:</B> <A
onclick="return top.js.OpenExtLink(window,event,this)"
href="mailto:baypiggies@python.org"
target=_blank>baypiggies@python.org</A><BR><B>Subject:</B> [Baypiggies]
newbie question - automating my reporting tasks<BR></FONT><BR> </DIV>
<DIV><SPAN>
<DIV></DIV>
<DIV>Hello all,</DIV>
<DIV> </DIV>
<DIV>It does seem that Python is easier to lean than PERL. and I like the
interpreter.</DIV>
<DIV> </DIV>
<DIV>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. </DIV>
<DIV> </DIV>
<DIV>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. </DIV>
<DIV> </DIV>
<DIV>Thanks in advance,</DIV>
<DIV>Alden</DIV></SPAN></DIV></BLOCKQUOTE></DIV></BLOCKQUOTE></DIV><BR></BLOCKQUOTE></BODY></HTML>