Guest User

Untitled

a guest
Jan 24th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. file = open('file.txt', 'r') #в файле 20 строк
  2. for i in range(40):
  3. line = file.readline()
  4. file.close()
  5.  
  6. from itertools import cycle, islice
  7.  
  8. with open('file.txt') as fh:
  9. for line in islice(cycle(fh), 40):
  10. ...
  11.  
  12. with open('file.txt', 'r') as f:
  13. for i in range(40):
  14. line = f.readline()
  15.  
  16. # Возвращаемся к началу файла
  17. f.seek(0)
  18.  
  19. with open('file.txt', 'r') as f:
  20. for line in f:
  21. print(repr(line))
  22.  
  23. # Возвращаемся к началу файла
  24. f.seek(0)
  25.  
  26. print("Еще раз!")
  27.  
  28. for line in f:
  29. print(repr(line))
Add Comment
Please, Sign In to add comment