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
#4
This helps, @knackwurstbagel. My loop in its current form doesn’t actually do anything, as you’ve explained. But by modifying it slightly, also as you’ve suggested, it shows how the split function works. Here is the new output with your suggested modification:

Quote:['Welcome', 'to', 'your', 'First', 'Exam', 'Recruit.']
['Only', 'the', 'best', 'recruits', 'can', 'become', 'agents.']
['Do', 'you', 'have', 'what', 'it', 'takes?']
['We', 'will', 'test', 'your', 'knowledge', 'with', 'this', 'field', 'readiness', 'exam.']
['It', 'should', 'be', 'pretty', 'simple,', 'since', 'you', 'only', 'know', 'the', 'basics', 'so', 'far.']
["Let's", 'get', 'started.']
['Best', 'of', 'luck', 'recruit.']
It should be pretty simple, since you only know the basics so far.

I see now. The lines in the text file are split according to white space, not individual characters.

@Larz60+: Your code is elegant and far superior than mine. You mentioned buffering. I don’t really understand what you mean by file buffering and file pointers but it may have to do with the Jupyter Notebook tool that I’m doing this exercise with. You’ve done a terrific job re-writing my script on your own terms, but if I wanted to retain my somewhat novice approach while keeping my general awkward syntax, how would you modify my script to avoid making the mistake I made with the file-pointer buffer issue?
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 Drone4four - Aug-16-2018, 01:18 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,226 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Delete multiple lines from txt file Lky 6 2,459 Jul-10-2022, 12:09 PM
Last Post: jefsummers
  python-docx: preserve formatting when printing lines Tmagpy 4 2,309 Jul-09-2022, 01:15 AM
Last Post: Tmagpy
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,834 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  Editing text between two string from different lines Paqqno 1 1,369 Apr-06-2022, 10:34 PM
Last Post: BashBedlam
  failing to print not matched lines from second file tester_V 14 6,410 Apr-05-2022, 11:56 AM
Last Post: codinglearner
  Extracting Specific Lines from text file based on content. jokerfmj 8 3,228 Mar-28-2022, 03:38 PM
Last Post: snippsat
  Converted Pipe Delimited text file to CSV file atomxkai 4 7,244 Feb-11-2022, 12:38 AM
Last Post: atomxkai
  raspberry use scrolling text two lines together fishbone 0 1,504 Sep-06-2021, 03:24 AM
Last Post: fishbone
  Importing a function from another file runs the old lines also dedesssse 6 2,703 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