python列表生成多个号码_python按需生成固定数量电话号码并保存为excel(不重复)...
Apple iPhone 11 (A2223) 128GB 黑色 移動聯通電信4G手機 雙卡雙待
4999元包郵
去購買 >
如果設置了本地環境變量,可直接執行
#coding=utf-8
# -*- coding: utf-8 -*-
import xlwt
import random
numList = []
#設置表格樣式
def set_style(name,height,bold=False):
style = xlwt.XFStyle()
font = xlwt.Font()
font.name = name
font.bold = bold
font.color_index = 4
font.height = height
style.font = font
return style
def generatorNum():
list = ['139', '188', '185', '136', '155', '135', '158', '151', '152', '153']
str = '0123456789'
for i in range(2000): #在這里改所需數量
global numList
numList.append(random.choice(list) + "".join(random.choice(str) for i in range(8)))
#寫Excel
def write_excel():
f = xlwt.Workbook()
sheet1 = f.add_sheet('number',cell_overwrite_ok=True)
row0 = ["number"]
global numList
print(numList)
colum0 = numList
#寫第一行
for i in range(0,len(row0)):
sheet1.write(0,i,row0[i],set_style('Times New Roman',220,True))
#寫第一列
for i in range(0,len(colum0)):
sheet1.write(i+1,0,colum0[i],set_style('Times New Roman',220,True))
f.save('test.xls')
if __name__ == '__main__':
generatorNum()
write_excel()
原文鏈接:https://segmentfault.com/a/1190000020310778
總結
以上是生活随笔為你收集整理的python列表生成多个号码_python按需生成固定数量电话号码并保存为excel(不重复)...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python调用java方法_pytho
- 下一篇: 治疗咳嗽的药物有哪些