码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-06-17 12:31:27      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:name   utf-8   class   col   for   import   color   on()   pat   

 

在文件夹中创建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()

 

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

标签:name   utf-8   class   col   for   import   color   on()   pat   

原文地址:https://www.cnblogs.com/huanu/p/9192455.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!