Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- file = open('file.txt', 'r') #в файле 20 строк
- for i in range(40):
- line = file.readline()
- file.close()
- from itertools import cycle, islice
- with open('file.txt') as fh:
- for line in islice(cycle(fh), 40):
- ...
- with open('file.txt', 'r') as f:
- for i in range(40):
- line = f.readline()
- # Возвращаемся к началу файла
- f.seek(0)
- with open('file.txt', 'r') as f:
- for line in f:
- print(repr(line))
- # Возвращаемся к началу файла
- f.seek(0)
- print("Еще раз!")
- for line in f:
- print(repr(line))
Add Comment
Please, Sign In to add comment