Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class FileIterator:
- def __init__(self, filename: str):
- self.filename = filename
- self.file = open(filename, "r", encoding="utf8")
- def __iter__(self):
- return self
- def __next__(self):
- line = self.file.readline()
- if not line:
- self.file.close()
- raise StopIteration
- return line.strip()
- iter = FileIterator("osoby.txt")
- print(next(iter))
- print("---" * 10)
- for line in iter:
- print(line)
- # print(next(iter))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement