(八)Python脚本
1.在 linux4 上编写/root/createfile.py 的 python3 脚本,创建 20 个文件/root/python/file101 至/root/python/file120,如果文件存在,则删除后再创建;每个文件的内容同文件名,如 file101 文件的内容为“file101”。
import os
os.mkdir(‘//root//python’)
os.chdir(‘//root//python’)
for i in range(101, 121):
file_name ="file"+ str(i)
print(file_name)
with open(file_name, 'w') as f:
message_buffer =str(file_name)
f.write(message_buffer)
f.write('\n')