import pyperclip # 交易数量 dealNum = 2 # 读取单交易信息并复制到剪贴板 with open(r'test.txt', encoding='utf-8') as f: txt = f.read() pyperclip.copy(txt) # 生成批量交易 res = '' dealInfo = pyperclip.paste() for i in range(dealNum): res = '{}\n{}'.format(res, dealInfo) print(res) |
<tag>测试报文</tag> <tag>测试报文</tag> |
import random # 随机生成8位交易号 traNo = random.sample(range(10**7, 10**8), 5) print(traNo) |
[69244291, 71447069, 95104116, 91919619, 50861438] |
import re # file:待替换文件 # numberList:随机交易号列表 def alter_file(file, numberList): fileData = '' i = 0 with open(file, 'r', encoding='utf-8') as f: for line in f: if '<tag>' in line: newStr = '<tag>{}</tag>'.format(numberList) i += 1 line = re.sub(r'<tag>\d+</tag>', newStr, line) fileData += line with open('result.txt', 'w', encoding='utf-8') as f: f.write(fileData) |
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) | Powered by Discuz! X3.2 |