from faker import Faker f = Faker(locale='zh_CN') def getWords(name=None): ''' 获取随机汉字 :param name: :return: ''' worlds = f.word() + f.word() if name: worlds = name + '_' + worlds return worlds def getStr(name=None): ''' 获取随机字符串 :param name: :return: ''' worlds = f.pystr() if name: worlds = name + '_' + worlds return worlds def getLenStr(name): ''' 返回字符串长度 :param name: :return: ''' return len(name) # 参考 https://www.jianshu.com/p/6bd6869631d9