在文件夹中创建10个文本,以数字给他们命名。

在文件夹中创建10个文本,以数字给他们命名。

 1 #! /usr/bin/env python
 2 # -*- coding:utf-8 -*-
 3 import os
 4 
 5 def text_creation():
 6     path = 'd://a//'
 7     for name in range (1,11):
 8         with open(path + str(name) + '.txt','w') as text: #写文件
 9             text.write(str(name))
10             text.close()
11             print ('创建'+ str(name) + '.txt成功')
12 text_creation()

猜你喜欢

转载自www.cnblogs.com/huanu/p/9192455.html