Python Forum

Full Version: create objects from file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi
I have created a class student and a constructor where there are 4 arguments ie, name and 3 subjects.
I have created an object with name and marks of 3 subjects. It worked fine and gave desired output.
Now i want to read students name and marks from a txt file. I open and read txt file but i am unable to break the line to name and marks. Can anyone solve this problem
my txt file info is
first,last,60,40,80
...................
faizahsan66 - Please start your own post. This one belongs to the creator Zork_3.
Yours won't get answered sooner by pirating someones post.
Thanks for letting me know the policy of this forum. Sorry and have a good day
Use the split method to break the lines apart: 'first,last,60,40,80'.split(',') will give you the list ['first', 'last', '60', '40', '80']. Then you can use int() to convert the last three items to integer: int('60') will give you 60.