How to create a file name with the current date & time in Python?

后端 未结 6 1359
北海茫月
北海茫月 2020-12-07 07:40

Here is a functional code (create file with success)

sys.stdout = open(\'filename1.xml\', \'w\')

Now I\'m trying to name the file with the cu

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-07 08:27

    I'm surprised there is not some single formatter that returns a default (and safe) 'for appending in filename' - format of the time, We could simply write FD.write('mybackup'+time.strftime('%(formatter here)') + 'ext'

    "%x" instead of "%Y%m%d-%H%M%S"
    

提交回复
热议问题