[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

# 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':
#If this the first row
  if master_row == 0:
  	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]:
#If this is a new SID
   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:
  	 count += 1

Hope this helps.

-Best Regards-

-Quentin Hartman-
Technology Coordinator
South Lane School District 45j3
Cottage Grove, Oregon

More information about the K12OSN mailing list