批量创建用户名密码(数组)
import random,string res_lit=[] for i in range(100): rand_num = str(random.randint(0, 9999)) rand_num=rand_num.zfill(4) username="zr"+rand_num password="jcyf1234*" res=''.join([username,",",password])+ '\n' if res not in res_lit: res_lit.append(res) f=open('username3.txt','w').writelines(res_lit)
Python_write和writelines的区别
1 write()需要传入一个字符串做为参数,否则会报错
2 writelines()既可以传入字符串又可以传入一个字符序列,并将该字符序列写入文件
注意 :writelines必须传入的是字符序列,不能是数字序列
如:list_1023 = [1,2,3,4,5]
报错:TypeError: write() argument must be str, not list