最近在写一个小程序,需要获取指定长度的字符串  number float time等类型的数据,所以自己封装了一个函数

#生成指定长度的字符串 def random_char(length,flag):#flag为0表示number,1表示字符串类型,2表示time类型
result = '' chars =
'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789' nums =
'123456789' numlength = len(nums) - 1 charlength = len(chars) - 1 str_tmp =
Random() if flag == 1: result = datetime.datetime.now().strftime("%Y-%m-%d
%H:%M:%S") return result elif flag == 2: result =
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f") return result elif
flag == 3 or flag == 4: for i in range(int(length)): if flag == 3:
#1表示date,2表示timestamp,3表示number,4表示varchar2 nvarchar2 long char,5表示float result
+= nums[str_tmp.randint(0,numlength)] elif flag == 4: result +=
chars[str_tmp.randint(0,charlength)] elif flag == 5:#length == P20S8 即PRECISION
= 20 SCALE = 8 precision,scale = get_precision_scale(length) integer_max =
int(precision) - int(scale) for j in range(integer_max): result +=
nums[str_tmp.randint(0,numlength)] result += '.' for k in range(int(scale)):
result += nums[str_tmp.randint(0,numlength)] return result

技术
©2019-2020 Toolsou All rights reserved,
基于神经网络的车辆牌照字符识别技术Java基础(三) String深度解析 dedecms网站被黑 劫持到其他网站如何解决精准手机号抓取,运营商大数据利用梆梆加固逻辑漏洞取巧脱壳QT 删除目录及文件Java小明A+B苹果不送充填器耳机真为环保?可能还是为了赚钱吧在Pytorch上使用summaryC#中字典的排序方法