首页 > 解决方案 > 如何将终端的输出写入具有格式的文件?

问题描述

我想将脚本的结果保存到文件中。脚本示例:

import os

def scan_ip():
    ip2 = raw_input('Enter ip of target: ')
    target = 'nmap -sP {}'.format(ip2)
    os.system(target + > '123.txt')

标签: pythonpython-2.7

解决方案


with open('123.txt', 'w') as my_file:
    my_file.write(target)

推荐阅读