Best way to generate random file names in Python

前端 未结 11 2105
囚心锁ツ
囚心锁ツ 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:31

    >>> import random
    >>> import string    
    >>> alias = ''.join(random.choice(string.ascii_letters) for _ in range(16))
    >>> alias
    'WrVkPmjeSOgTmCRG'
    

    You could change 'string.ascii_letters' to any string format as you like to generate any other text, for example mobile NO, ID...

提交回复
热议问题