python 如何新建一个新的File?

python 如何新建一个新的File?,第1张

#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 os

basepath = 升好凯'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()

望采纳袜卖,谢谢支持!


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/8149380.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存