Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
create objects from file
#1
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
...................
Reply
#2
faizahsan66 - Please start your own post. This one belongs to the creator Zork_3.
Yours won't get answered sooner by pirating someones post.
Reply
#3
Thanks for letting me know the policy of this forum. Sorry and have a good day
Reply
#4
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 - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create Choices from .ods file columns cspower 3 518 Dec-28-2023, 09:59 PM
Last Post: deanhystad
  Recommended way to read/create PDF file? Winfried 3 2,781 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  Use PM4PY and create working file thomaskissas33 0 572 Nov-14-2023, 06:53 AM
Last Post: thomaskissas33
  Create csv file with 4 columns for process mining thomaskissas33 3 691 Nov-06-2023, 09:36 PM
Last Post: deanhystad
  create exe file for linux? korenron 2 908 Mar-22-2023, 01:42 PM
Last Post: korenron
  my first file won't create itself MehHz2526 2 858 Nov-27-2022, 12:58 AM
Last Post: MehHz2526
  Create multiple/single csv file for each sql records mg24 6 1,317 Sep-29-2022, 08:06 AM
Last Post: buran
Sad pandas writer create "corrupted" file freko75 1 2,735 Jun-14-2022, 09:57 PM
Last Post: snippsat
  create new log file on logging? korenron 6 2,202 Mar-22-2022, 07:14 AM
Last Post: korenron
  Create zip file from the BLOB column in ORACLE DB nnsatpute 2 1,876 Dec-31-2021, 11:00 AM
Last Post: ibreeden

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020