Best way to generate random file names in Python

前端 未结 11 2098
囚心锁ツ
囚心锁ツ 2020-12-04 08:48

In Python, what is a good, or the best way to generate some random text to prepend to a file(name) that I\'m saving to a server, just to make sure it does not overwrite. Tha

11条回答
  •  悲哀的现实
    2020-12-04 09:16

    I personally prefer to have my text to not be only random/unique but beautiful as well, that's why I like the hashids lib, which generates nice looking random text from integers. Can installed through

    pip install hashids

    Snippet:

    import hashids
    hashids = hashids.Hashids(salt="this is my salt", )
    print hashids.encode(1, 2, 3)
    >>> laHquq
    

    Short Description:

    Hashids is a small open-source library that generates short, unique, non-sequential ids from numbers.

提交回复
热议问题