首页 > 技术文章 > python: shutil模块 -拷贝文件

xuehuahongmei 2016-10-21 10:59 原文

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)

 

推荐阅读