python代码实现自动化测试中字符串自动生成
import datetime
import random
import string
t1 = datetime.datetime.today()
t1 = t1.strftime("%Y%m%d%H%M%S")
print(t1)
print("大小写字母:" + string.ascii_letters)
print("小写字母:" + string.ascii_lowercase)
print("大写字母:" + string.ascii_uppercase)
print("数字:" + string.digits)
print("特殊符号:" + string.punctuation)
print("可打印的字符:" + string.printable)
print("空格字符:" + string.whitespace)
StringS = ''.join(random.sample(string.digits+string.ascii_letters,32))
print(StringS)
#指定字符集输出
seed = "1234567890"
str1 = []
for i in range(18):
str1.append(random.choice(seed))
String1 = ''.join(str1)
print(String1)
#指定长度输出
def newstr(len):
seed="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
str1=[]
for i in range(len):
str1.append(random.choice(seed))
string2 = ''.join(str1)
print(string2)
#len22 = int(input("请输入字符串的长度:"))
newstr(18)
javascript
posted on 2021-11-13 22:43 sunny_2016 阅读(128) 评论(0) 编辑 收藏 举报