1.新建三级目录,第一级是去年的年份,第二级是去年的月,第三级为去年的日,在日的文件中写入今年的时分秒 import os import time import shutil def create_file(path): gettime=time.localtime() #获得当前时间的列表 getyear=gettime.tm_year-1 #获取去年的时间 getmon=gettime.tm_mon-1 #获得去年月 getday=gettime.tm_mday-1 #获得去年的日 if g
说明:本次代码是在Linux下执行的,windows也可以用,把添加用户密码的命令改成windows的就ok了 用Python新建用户并产生随机密码 import passwd_name as pn #导入随机产生名字密码模块 import os f = open("/tmp/userlist.txt","w") 将用户名.密码写入该文件中 for i in range(0,3): #添加3位用户 username=pn.random_name() os.syste
Python读取txt文件,有两种方式: (1)逐行读取 data=open("data.txt") line=data.readline() while line: print line line=data.readline() (2)一次全部读入内存 data=open("data.txt") for line in data.readlines(): print line