Python Forum
Skipping line in text without Restarting Loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Skipping line in text without Restarting Loop
#5
You can provide a default value for next() to return when the a StopIteration exception occurs. For bowlofred's example you would use: next_word = next(words, "")
bowlofred likes this post
Reply


Messages In This Thread
RE: Skipping line in text without Restarting Loop - by deanhystad - Apr-05-2022, 04:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  File loop curiously skipping files - FIXED mbk34 10 867 Feb-10-2024, 07:08 AM
Last Post: buran
  How do I properly implement restarting a multithreaded python application? MrFentazis 1 640 Jul-17-2023, 09:10 PM
Last Post: JamesSmith
  while loop not working-I am using sublime text editor mma_python 4 1,173 Feb-05-2023, 06:26 PM
Last Post: deanhystad
  Trying to loop through code to plot seaborn line plots across multiple subplots eyavuz21 0 1,704 Dec-05-2022, 10:46 AM
Last Post: eyavuz21
  Graphic line plot with matplotlib, text file in pytho khadija 2 1,413 Aug-15-2022, 12:00 PM
Last Post: khadija
  Find and delete above a certain line in text file cubangt 12 3,536 Mar-18-2022, 07:49 PM
Last Post: snippsat
  CSV to Text File and write a line in newline atomxkai 4 2,736 Feb-15-2022, 08:06 PM
Last Post: atomxkai
  How to prevent python from going to new line in for loop? idknuttin 3 4,971 Feb-11-2022, 05:40 AM
Last Post: deanhystad
  How to make for loop display on 1 Line Extra 3 1,462 Jan-12-2022, 09:29 PM
Last Post: Extra
  python seems to be skipping lines of code alansandbucket 1 4,187 Jun-22-2021, 01:18 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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