python3 利用当前时间、随机数产生一个唯一的数字作为文件名


一、python3 利用当前时间、随机数产生一个唯一的数字作为文件名


代码如下:

#-*-coding:utf-8-*-

#python3自动生成文件名
from datetime import *
import time
import random
for i in range(0,1):
    nowTime = datetime.now().strftime("%Y%m%d%H%M%S")#生成当前的时间
    randomNum = random.randint(0,100)#生成随机数n,其中0<=n<=100
    if randomNum<=10:
        randomNum = str(0) + str(randomNum)
    uniqueNum = str(nowTime) + str(randomNum)
    print(uniqueNum)



二、参考链接:

http://blog.csdn.net/yongh701/article/details/46912391

猜你喜欢

转载自blog.csdn.net/qiang12qiang12/article/details/72599110