• Python类


      说到分享自然不能少了这个

      但其实也没什么好说的我就分享一个我做的小项目给大家看一下吧,就是上一节说的那个造假姓名数据,自己想一次性 生成多少就是多少

    import random
     
    fN=[] #姓
    lN1=[] #一个字的名
    lN2=[] #两个字的名
    with open('C:/Users/zhaopf.DIGIWIN/Desktop/firstName.txt') as fFile:#姓
    fN=fFile.read().split(' ')
    # print(fN)
    # for line in fFile.readline():
    # for l in line:
    # if len(l)==1:
    # lN1.append(l)
    with open('C:/Users/zhaopf.DIGIWIN/Desktop/lastName.txt') as lFile:#名
    lN=lFile.read().split(' ')
    for ln in lN:
    if len(ln)==1:
    lN1.append(ln)
    else:
    lN2.append(ln)
    # print(lN1)
    # print(lN2)
    class FakeUser:
    fullName=''
    sex=''
    def fakeName(self,num,isOne=False,isTwo=True):
    while num>=0:
    if isOne:
    FakeUser.fullName=random.choice(fN)+random.choice(lN1)
    yield FakeUser.fullName
    num-=1
    # 这个要注意一下就是说这个一定要加个类或者是self,不然就不确定是哪一个的变量,
    # 如果上面没有定义并且下面也不写self就会报错
    elif isTwo:
    FakeUser.fullName=random.choice(fN)+random.choice(lN2)
    yield FakeUser.fullName
    num -= 1
    else:
    FakeUser.fullName=random.choice(fN)+random.choice(lN1)+random.choice(lN2)
    yield FakeUser.fullName
    num -= 1
    def fakeSex(self,num):
    while num >= 0:
    sexs=['男','女','未知']
    FakeUser.sex=random.choice(sexs)
    yield FakeUser.sex
    num -= 1
    class SonsUser(FakeUser):
    number=''
    def numberFollow(self,num,few=True,aLot=False):
    while num >= 0:
    if few:
    SonsUser.number=random.randrange(1,50)
    yield SonsUser.number
    num -= 1
    elif aLot:
    SonsUser.number=random.randrange(200,1000)
    yield SonsUser.number
    num -= 1
    su1=SonsUser()
    num=66
    listName=su1.fakeName(num,False,True)
    listSex=su1.fakeSex(num)
    listFollow=su1.numberFollow(num,few=False,aLot=True)
    while num>0:
    print("the name of this user is {} and age is {}".format(listName.__next__(),listSex.__next__()))
    print("the follow number of this user is {}".format(listFollow.__next__()))
    num -= 1
     
     
  • 相关阅读:
    通过如何通过js实现复制粘贴功能
    通过localstorage和cookie实现记录文章的功能
    HTML5表单提示placeholder属性兼容IE
    html5跨域数据传递(postMessage)
    js获取当前指定的前几天的日期(如当前时间的前七天的日期)
    html5本地存储(localStorage)使用介绍
    原生js动画效果(源码解析)
    如何通过js和jquery获取图片真实的宽度和高度
    echart-图表位置改变
    echart-渐变色背景
  • 原文地址:https://www.cnblogs.com/zpfXdd/p/7816454.html
Copyright © 2020-2023  润新知