Python Forum
Printing lines in a basic text file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Printing lines in a basic text file
#5
Another possible solution, without itertools:

>>> with open('field.txt', 'r') as quotes:
...    for i, v in enumerate(quotes.readlines()):
...        if i == 4:
...            print(v)
...            break              # if line 5 reached you don't want iterate anymore
...
It should be pretty simple, since you only know the basics so far.
I should be pretty much in line with your original syntax.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Printing lines in a basic text file - by Drone4four - Aug-16-2018, 12:08 AM
RE: Printing lines in a basic text file - by perfringo - Aug-16-2018, 04:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,194 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Delete multiple lines from txt file Lky 6 2,409 Jul-10-2022, 12:09 PM
Last Post: jefsummers
  python-docx: preserve formatting when printing lines Tmagpy 4 2,241 Jul-09-2022, 01:15 AM
Last Post: Tmagpy
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,793 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  Editing text between two string from different lines Paqqno 1 1,361 Apr-06-2022, 10:34 PM
Last Post: BashBedlam
  failing to print not matched lines from second file tester_V 14 6,328 Apr-05-2022, 11:56 AM
Last Post: codinglearner
  Extracting Specific Lines from text file based on content. jokerfmj 8 3,185 Mar-28-2022, 03:38 PM
Last Post: snippsat
  Converted Pipe Delimited text file to CSV file atomxkai 4 7,180 Feb-11-2022, 12:38 AM
Last Post: atomxkai
  raspberry use scrolling text two lines together fishbone 0 1,493 Sep-06-2021, 03:24 AM
Last Post: fishbone
  Importing a function from another file runs the old lines also dedesssse 6 2,686 Jul-06-2021, 07:04 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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