python 建立文件夹并新建txt文件

python 建立文件夹并新建txt文件

import os

def new_txt():
b = os.getcwd() + '\\test_txt\\'
print("Created directory:"+ "test_txt")
print("The created TXT files:")
if not os.path.exists(b):
os.makedirs(b)
for file in range(1,20):
print(str(file)+'.txt')

open(b+str(file)+'.txt', "w")

if __name__ == '__main__':

new_txt()

效果如图:


猜你喜欢

转载自blog.csdn.net/qq_22690543/article/details/80822968