Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 create objects from file
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
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.
Craig "Ichabod" O'Brien -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures


Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How do I write class objects to a file in binary mode? Exsul1 7 463 Sep-14-2019, 09:33 PM
Last Post: snippsat
  Create file archive that contains crypto hash ED209 1 191 May-29-2019, 03:05 AM
Last Post: heiner55
  error creating new object after loading pickled objects from file arogers 2 460 Feb-02-2019, 10:43 AM
Last Post: Larz60+
  Python Directory and File Create Error basic_learner 1 447 Dec-16-2018, 11:03 AM
Last Post: buran
  How can Read text file and create array? puneet102 1 595 May-22-2018, 06:41 PM
Last Post: snippsat
  Recursively create a file digitalquake 19 5,672 Dec-07-2016, 06:08 PM
Last Post: Larz60+

Forum Jump:

Users browsing this thread: 1 Guest(s)