好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Python中的POST/GET包构建以及随机字符串的生成

现在,我们来用Python,创建GET包和POST包。

知道了这步,我们可以很简单的编写一个随机字符串的程序了,

from random import Random
def random_str(randomlength):
    str = ''
    chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789'
    length = len(chars) - 1
    random = Random()
    for i in range(randomlength):
        str+=chars[random.randint(0, length)]
    return str 

显然当调用此函数时应该给出随机字符串长度。

当然,我们也可以通过修改chars中的字符来定义随机字符串中的字符。

(二) 程序运行时间

我们现在给出一个非常不精确的程序时间计算方法,

from time import clock as now
start = now()
finish = now()
run_time = finish - start
print run_time 

查看更多关于Python中的POST/GET包构建以及随机字符串的生成的详细内容...

  阅读:42次