create objects from file - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: create objects from file (/thread-4535.html) |
create objects from file - faizahsan66 - Aug-23-2017 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 ................... RE: Newbie Question - Larz60+ - Aug-23-2017 faizahsan66 - Please start your own post. This one belongs to the creator Zork_3. Yours won't get answered sooner by pirating someones post. RE: create objects from file - faizahsan66 - Aug-24-2017 Thanks for letting me know the policy of this forum. Sorry and have a good day RE: create objects from file - ichabod801 - Aug-24-2017 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 .
|