I've been rewriting some of my old c++ programs in python for the learning experience, but I've hit a snag.
In the original program, classes (school classes, not programming classes) are sorted based on the number of prerequisites. However, the data (class name, number, preReq's, coReq's, hours) were stored in a text file and then read into a struct.
I eventually found a way to link two sets of data types with a list made up of tuples, but this is making it hard to compare a class (school class) to another as they are both members of the same list (as opposed to n-number of different structs).
test =[('chem',2),('bio',1)] (I also figured out how to sort using itemgrabber which was the other problem).
as opposed to test=('chem',2) test=('bio',1)
or perhaps more ideally test is an object with the variables name, hrs, etc, but I've yet to find this in the documentation.
Is it possible to create dynamically allocated objects based on file input (in python)? Further, is there a better way to read in data from a file? So far, the best I have been able to do is pull in the entire file into one huge list and then try a break in down from there. The original data files from c++ where either binary (my stuct files) or delimited with white space or special characters.
Page 1 of 1
2 Replies - 1901 Views - Last Post: 24 February 2010 - 10:20 AM
Replies To: File input into something struct-like in python
Page 1 of 1