python: shutil模块 -拷贝文件

import shutil #拷贝文件
#存在文档1文件
shutil.copyfile('文档1','新文件')

随机验证码-4位

import random
random_code=''
for i in range(4): #4位验证码
    current =random.randrange(0,4)
    if current==i:#如果是当前i的值
        res=chr(random.randint(65,90))#就返回一个字母
    else:
        res=random.randint(0,9)
    random_code+=str(res)
print(random_code)

 

posted @ 2016-10-21 10:59  梅子472  阅读(571)  评论(0编辑  收藏  举报