长期网站外包,卖网站怎样做,大气网络公司网站模板,怎么做内网网站(转载)https://www.xshell.net/python/python_open.htmlPosted by 破冰 on 2013-9-17 17:29 Tuesday一、用Python创建一个新文件#xff0c;内容是从0到9的整数, 每个数字占一行#xff1a;#pythonfopen(f.txt,w) # r只读#xff0c;w可写#xff0c;a追加内容是从0到9的整数, 每个数字占一行#pythonfopen(f.txt,w) # r只读w可写a追加for i in range(0,10):f.write(str(i)\n). . . f.close()二、文件内容追加从0到9的10个随机整数#pythonimport randomfopen(f.txt,a)for i in range(0,10):f.write(str(random.randint(0,9))). . .f.write(\n)f.close()三、文件内容追加从0到9的随机整数, 10个数字一行共10行#python import random fopen(f.txt,a) for i in range(0,10):. . . for i in range(0,10):f.write(str(random.randint(0,9))). . . f.write(\n). . . f.close()四、把标准输出定向到文件#python import sys sys.stdout open(stdout.txt, w)例子查看22端口情况并将结果写入a.txt#!/usr/bin/python#codingutf-8import osimport timeimport sysfopen(a.txt,a)f.write(os.popen(netstat -nltp | grep 22).read())f.close()