1、python压力测试中经常数据要参数化,同时不希望一条一条的顺序执行或并发
2、python随机读取文件中的某一行内容
实现步骤:
1、实验数据
2、执行代码
#encoding=utf-8
#随机数,随机读取每一行的数据
import linecache
import random
for i in xrange(1,5):#for循环几次
a = random.randrange(1, 9) #1-9中生成随机数
print a
#从文件poem.txt中对读取第a行的数据
theline = linecache.getline(r'poem.txt', a)
print theline
3、打印结果