Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 3, 2018 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/a2f836c396a6c13b1a5be82f5c244e10 to your computer and use it in GitHub Desktop.
Save Fhernd/a2f836c396a6c13b1a5be82f5c244e10 to your computer and use it in GitHub Desktop.
Leer y escribir datos binarios. OrtizOL.
def generador_fibonacci():
fib1 = 0
fib2 = 1
while True:
yield fib2
fib1, fib2 = fib2, fib1 + fib2
with open('fibonaccis.bin', 'wb') as f:
contador = 1
for fib in generador_fibonacci():
f.write(bytes(str(fib) + ' ', 'utf-8'))
if contador == 10:
break
contador += 1
with open('fibonaccis.bin', 'rb') as f:
print(f.read(), end='\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment