2 Replies - 1974 Views - Last Post: 24 February 2010 - 10:20 AM Rate Topic: -----

#1 RoseWyvern  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 17
  • Joined: 29-December 09

File input into something struct-like in python

Posted 23 February 2010 - 05:45 PM

Hello everyone!
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).

E.G.

test =[('chem',2),('bio',1)] (I also figured out how to sort using itemgrabber which was the other problem).

as opposed to test[0]=('chem',2) test[1]=('bio',1)

or perhaps more ideally test[0] 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.

Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: File input into something struct-like in python

#2 RoseWyvern  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 17
  • Joined: 29-December 09

Re: File input into something struct-like in python

Posted 23 February 2010 - 06:56 PM

Wow, so sorry. I completely missed the class section when I was reading through the python documentation. Again, sorry.
Was This Post Helpful? 0
  • +
  • -

#3 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: File input into something struct-like in python

Posted 24 February 2010 - 10:20 AM

It's ok boss. If you have any trouble with classes, feel free to post it on this post.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1