#python
f=open('f.txt','w') # r只读,判型旁w可写,a追加
for i in range(0,10):f.write(str(i)+'\n')
例子:
#!/usr/bin/python
#coding=utf-8
import os
import time
import sys
f=open('a.txt','a')
f.write(os.popen('netstat -nltp | grep 22').read())
f.close()
扩展资料:关于上述创建文件,文件内容追加
#python
import random
f=open('f.txt','a')
for i in range(0,10):f.write(str(random.randint(0,9)))
. . .
f.write('\n')
f.close()
或者
#python
import rando
f=open('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()
代码如下,就是这么简单:
import osbasepath = 升好凯'c:\data'
for line in 吵唤open('a.txt'):
basename = line.strip()
folder = os.path.join(basepath, basename)
filename = os.path.join(folder, basename)
os.mkdir(folder)
open(filename, 'w').close()
望采纳袜卖,谢谢支持!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)