pythonfileiotxt

Execute script on one text file, and create new text file with output without cmd


Title is pretty self-explanatory. Currently I have:

with open('dwarf_fort.txt') as f:
    for minerals in f:
        mining_rig()

I need it to go from 'dwarf_fort.txt', execute the program and append the output into a new file. What am I missing here? Thank you.


Solution

  • This should work:

    with open('dwarf_fort.txt') as f, open('out_f.txt', mode='w') as f1:
        for minerals in f:
            f1.write(minerals)
    

    If the output file is still blank, do some checks: