I need to make this into a multi-dimensional array. I know I need to change presArray = Table1Builder(60, "STR") to presArray = Table1Builder(60,3, "STR")
I am not sure how to load it. Do I need three load statements? Help Please!
# Import string to use split function.
import string
# Imports TableBuilder for building the array
from Table1Builder import Table1Builder
def main():
# Creates variable for .txt file.
inFileName = "presidents.txt"
# Opens input files
inFile = open(inFileName, "r")
# Creates presArray
presArray = Table1Builder(60, "STR")
# Loop to LOAD the array. @@@@@@@@@@@@@@@@@@
ptr = 0
for nextRecord in inFile:
# Creates variables for data seperated by comas.
name, years, age = string.split(nextRecord, ",")
# Removes leading blank space from variable...years.
years = years[1:]
# Removes '\n' character from variable...age.
age = age[1:-1]
# LOAD name in the ARRAY ---------------
presArray(ptr, name)
# increment the array pointer
ptr = ptr + 1
# Loop to WRITE the array. @@@@@@@@@@@@@@@@@@
# NOTICE: we are using the ptr that counted our input records.
for indx in range(ptr):
# Display the fields.
print presArray(indx)
# Close the files.
inFile.close()
# Shows data was saved.
print
print 'Data was read from', inFileName
# Call the main function.
main()