Python3 uses the current time, random number to produce a unique number as the filename

Source: Internet
Author: User


Python3 Use the current time, random number to produce a unique number as a filename


The code is as follows:

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

#python3自动生成文件名 from
datetime import *
import time
import random to
I in Range (0,1):
    nowtime = DateTime.Now (). Strftime ("%y%m%d%h%m%s") #生成当前的时间
    randomnum = Random.randint (0,100) # Generates a random number n, where 0<=n<=100
    if randomnum<=10:
        randomnum = str (0) + str (randomnum)
    uniquenum = str ( Nowtime) + str (randomnum)
    print (uniquenum)



Second, the reference link:

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.