Advertisement
Fhernd

funcion-generadora-estado-extra.py

Jun 15th, 2018
1,634
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. from collections import deque
  2.  
  3. class HistorialLineas:
  4.     def __init__(self, lineas, longitud = 5):
  5.         self.lineas = lineas
  6.         self.historial = deque(maxlen=longitud)
  7.  
  8.     def __iter__(self):
  9.         for numero_linea, linea in enumerate(self.lineas, 1):
  10.             self.historial.append((numero_linea, linea))
  11.             yield linea
  12.  
  13.     def remover(self):
  14.         self.historial.clear()
  15.  
  16.  
  17. if __name__ == '__main__':
  18.     with open('python.txt', 'r') as f:
  19.         lineas = HistorialLineas(f)
  20.  
  21.         for linea in lineas:
  22.             if 'Software' in linea:
  23.                 for numero_linea, historial_linea in lineas.historial:
  24.                     print('{}:{}'.format(numero_linea, historial_linea), end='')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement