[K12OSN] script help please (OT)

Quentin Hartman qhartman at lane.k12.or.us
Mon May 23 16:05:08 UTC 2005


On Mon, 2005-05-23 at 10:21 -0400, Jimmy Schwankl wrote:
> What he would like is for the first line to have the next three lines  
> appended to it with the first item stripped out so that when he  
> imports the file into a spreadsheet all the data for each record is  
> on one line.

I solved a very similar problem for an internal student information
lookup system recently. Below is the relevant function from the program
that takes input from Pentamation (our student management system) and
uploads it into a local MySQL database. It is in Python. There might be
a more efficient way to do it. Lines starting with # are comments and
walk through the algorithm. It assumes the input data is sorted by SID,
so that all the information pertaining to one student is clumped
together. If you would like to see the whole script, I'd be happy to
send it to you off-list, but I think this is probably enough to get you
going:

# reads contents of input
def read_csv():
 open_csv = csv.reader(file('locator_card.csv'), quotechar="\"") 
 master_row = 0
 for row in open_csv:
#Throw away header information
  if row[0] == 'Student Id Number':
   continue
#If this the first row
  if master_row == 0:
  	master_list.append(row)
  	master_row += 1
#If the SID of the current row matches the last SID entered, append the
needed info to the row
  elif row[0] == master_list[master_row-1][0]:
  	master_list[master_row-1].append(row[13:17])
#If this is a new SID
  else:
   master_list.append(row)
   master_row += 1
#Padding rows to same length so data lines up right
 for row in master_list:
  if len(row) < 60:
  	pad = [' ',' ',' ',' ']
  	target = 60 - len(row)
  	count = 0
  	while count < target:
  	 row.append(pad)
  	 count += 1

Hope this helps.

-- 
-Best Regards-

-Quentin Hartman-
Technology Coordinator
South Lane School District 45j3
Cottage Grove, Oregon
(541)767-3778
http://www.slane.k12.or.us




More information about the K12OSN mailing list