This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Looping through a text file with an iterator  RSS feed

 
Carey Brown
Saloon Keeper
Posts: 2536
33
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just thought somebody might find this interesting/useful.
I wanted to use the new 'for' syntax to loop through all the lines in a text file; something I find myself doing quite often.

A simple example:


It required making two classes: FileLineIterable, and FileLineIterator.
You might find this useful as an example for implementing your own iterator class.





 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!