Python Forum
Extracting Reoccuring Row Titles
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extracting Reoccuring Row Titles
#1
Good Evening!

I've got basic python education but am working on my capabilities.

I'm attempting to parse out multiple data entries for a single series of rows that contain headings. I just want the data within the row, not the heading. Here is an example of the raw data, which is much-much longer in real life.


RAW DATA SET:
1: Jeff
2: 21
3: Mature
4: Another
5: Yo

1: Sarah
2: Girl
3: Friend
4: Fall
5: Test

1: Fred
2: Hey
3: No
4: Window
5: Fifty...

DESIRED OUTPUT: (Print rows that begin with 1 and 3)

Jeff
Mature

Sarah
Friend

Fred
No


Where I'm at with my code testing.

TextDoc = '/root/Documents/<docname>.txt'

f = open(TextDoc, 'r')

if 1 print.line
if 3 print.line

f.close()



Thanks in advance for any mentorship,

-Hier0phant
Reply
#2
For this I would use the startswith, split, and strip methods of strings.
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
  How to Make Unique .txt titles Lancaster 1 1,390 Jun-13-2019, 09:40 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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