daily pastebin goal
78%
SHARE
TWEET

Untitled

a guest Jan 24th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top