How can I optimize this python code - NO MEMORY?
Question: I wrote this python code:

    
    
    from itertools import product
    
    combo_pack = product("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890!&+*-_.#@", repeat = 8)
    myfile = open("lista_combinazioni.txt","w")
    for combo in combo_pack:
       combo = "".join(combo)
       combo = "%s\n" % (combo)
       myfile.write(combo)
    myfile.close()
    

How can I optimize it? After a long time it running, it crashing because there
isn't memory.


Answer: What's probably happening is your file buffer is filling up and it isn't
flushing to the file, thus using a lot of memory.

Try using this instead:

    
    
    myfile = open("lista_combinazioni.txt","w",1)
    

