Python:如何创建唯一的文件名? [英] Python: How to create a unique file name?

查看:129
本文介绍了Python:如何创建唯一的文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有两个选项的python网络表单-文件上传 textarea .我需要从每个值中获取值并将它们传递给另一个命令行程序.我可以轻松地通过文件上传选项传递文件名,但是我不确定如何传递textarea的值.

I have a python web form with two options - File upload and textarea. I need to take the values from each and pass them to another command-line program. I can easily pass the file name with file upload options, but I am not sure how to pass the value of the textarea.

我认为我需要做的是:

  1. 生成唯一的文件名
  2. 在工作目录中使用该名称创建一个临时文件
  3. 将从textarea传递的值保存到临时文件中
  4. 从我的python模块内部执行命令行程序,然后将临时文件的名称传递给它

我不确定如何生成唯一的文件名.有人可以给我一些有关如何生成唯一文件名的提示吗?任何算法,建议和代码行都会受到赞赏.

I am not sure how to generate a unique file name. Can anybody give me some tips on how to generate a unique file name? Any algorithms, suggestions, and lines of code are appreciated.

感谢您的关注

推荐答案

我认为您的问题不是很清楚,但是如果您需要的只是一个唯一的文件名...

I didn't think your question was very clear, but if all you need is a unique file name...

import uuid

unique_filename = str(uuid.uuid4())

这篇关于Python:如何创建唯一的文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆