Hay que aprender a leer los errores:
Traceback (most recent call last):
File "f.py", line 7, in <module>
main()
File "f.py", line 4, in main
archivo.write(bytearray(otra))
TypeError: 'str' object cannot be interpreted as an integer
Basicamente dice que le estas pasando un list a la funcion y esta esperaba un Integer o un string, si buscamos la documentacion de esa funcion dice que:
bytearray() Parameters
bytearray() takes three optional parameters:
source (Optional) - source to initialize the array of bytes.
encoding (Optional) - if the source is a string, the encoding of the string.
errors (Optional) - if the source is a string, the action to take when the encoding conversion fails (Read more: String encoding)
Hay varios ejemplos:
https://www.programiz.com/python-programming/methods/built-in/bytearrayEl ejemplo tendria que quedar asi:
def main():
otra=[f"{x}, Yo vivo en este mundo pero no pertenezco a las leyes de este mundo" for x in range(1,100_001)] with open("numeros.bin","wb") as archivo:
archivo.write(bytearray(''.join(otra),'utf-8'))
if __name__ == "__main__":
main()
Se realiza un join por que bytearray no puede recibir una Lista
Por cierto esos strings dificilmente van a ocupar menos espacio.