此模块生成临时目录

sptempdir的Python项目详细描述


函数参数:

sptempdir.TemporaryDirectory(suffix="", prefix="", dir=None, delete=True)

默认情况下,当函数为 关闭。

示例1:

name属性返回临时目录的名称。

importosfromsptempdirimportTemporaryDirectorywithTemporaryDirectory(prefix="prefbegin_",suffix="_suffend")astemp:print('temp.name:',temp.name)# retrieve the name temporary directoryprint('Inside:',os.path.exists(temp.name))print('Outside:',os.path.exists(temp.name))

终端输出:

$ temporary_directory.py
temp.name: /tmp/prefbegin_66XxiFkN6Nm4_suffend
Inside: True
Outside: False

例2:

importosfromsptempdirimportTemporaryDirectorytemp=TemporaryDirectory()print('temp.name:',temp.name)# retrieve the name temporary directoryprint('Tempdir exists:',os.path.exists(temp.name))temp.remove()# manually remove temporary directoryprint('Tempdir exists:',os.path.exists(temp.name))

终端输出:

$ temporary_directory.py
temp.name: /tmp/RCgAzfsATQnb
Tempdir exists: True
Tempdir exists: False

例3:

如果delete参数是delete=False,则临时目录不是 删除。

importosfromsptempdirimportTemporaryDirectorytemp=TemporaryDirectory(delete=False)print('temp.name:',temp.name)# retrieve the name temporary directoryprint('Tempdir exists:',os.path.exists(temp.name))temp.remove()# manually remove temporary directoryprint('Tempdir exists:',os.path.exists(temp.name))

终端输出:

$ temporary_directory.py
temp.name: /tmp/kWwCWn42NRsr
Tempdir exists: True
Tempdir exists: False

例4:

要在其中创建临时目录的特定dir

fromsptempdirimportTemporaryDirectorytemp=TemporaryDirectory(dir="/home/user/Desktop")print(temp.name)# retrieve the name temporary directory

终端输出:

$ temporary_directory.py
/home/user/Desktop/4ZdTvLNqVuyE

安装:

pip install sptempdir

许可证:

BSD

(s p)tempdir=(s实现pythontempdir


https://img.shields.io/travis/aleskrejcicz/sptempdir/master.svghttps://img.shields.io/pypi/v/sptempdir.svghttps://img.shields.io/pypi/pyversions/sptempdir.svghttps://img.shields.io/pypi/l/sptempdir.svg

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
javajaxb在嵌套节点中生成xmlns:xsi声明   java重定向到youtube以上传jsp上可用的视频   java提高了JVM和ANT的性能   java如何将返回的JSON数据放在HTML表单中   java如何发送XWWWFORMURLENCODE在重新授权   java为什么jvm XX:+EliminateAllocations失败   堆移除和重建方法?(爪哇)   Stanford NPL in Spark(Scala)应用程序运行到Java堆空间(Java.lang.OutOfMemoryError)   调试java中打开/关闭println的任何方式(详细模式)   java IntelliJ在鼠标悬停时显示JavaDocs工具提示   Olingo Odata Java中的自动扩展选项   json将postgres文本arry转换为java列表?   oop需要帮助推断Java代码   复选框的java添加操作侦听器AbstractTableModel   java如何从公共静态void main(String[]args)传递值   java从数据库中获取大值   java Processing 2.0电影从jar运行时无法打开电影文件   java如何在不使用应用程序的情况下刷新活动?   尝试将JSON解析为ListView时的Android:JSON parse:null对象引用