Advertisement
Fhernd

leer-escribir-datos-binarios.py

Jul 3rd, 2018
1,714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. def generador_fibonacci():
  2.     fib1 = 0
  3.     fib2 = 1
  4.  
  5.     while True:
  6.         yield fib2
  7.         fib1, fib2 = fib2, fib1 + fib2
  8.  
  9. with open('fibonaccis.bin', 'wb') as f:
  10.     contador = 1
  11.  
  12.     for fib in generador_fibonacci():
  13.         f.write(bytes(str(fib) + ' ', 'utf-8'))
  14.  
  15.         if contador == 10:
  16.             break
  17.  
  18.         contador += 1
  19.  
  20.  
  21. with open('fibonaccis.bin', 'rb') as f:
  22.     print(f.read(), end='\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement