生成50个用户名和密码,文件内容如下
username,password
test01,1111
test02,1111
test03,1111
test04,1111
test05,1111
test06,1111
test07,1111
test08,1111
test09,1111
...................
test50,1111
代码如下
# coding=gbk
'''
filepath 生成的文件
usernameTitle 'username'
pwdTitle 'password'
username 用户名
password 密码
count 用户数量
separator 用户名和密码之间的分割符
'''
def createUserdata(filepath,usernameTitle,pwdTitle,username,password,count,separator):
file_object = open(filepath, 'w')
userdata=getUserdata(username,password,count,separator)
file_object.write(usernameTitle+separator+pwdTitle+"\n")
file_object.write(userdata)
file_object.close()
def getUserdata(username,pwd,count,separator):
userdata=''
for i in range(1,count+1):
if i <10:
userdata=userdata+username+'0'+str(i)+separator+str(pwd)+"\n"
else:
userdata=userdata+username+str(i)+separator+str(pwd)+"\n"
return userdata
createUserdata(r"E:\lr\data\userdata.dat",'username','password','test',1111,50,',')