此模块生成临时目录

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第三方库


热门话题
安卓为什么Java AudioEffect不支持双簧管?   增加内存后出现java IntelliJ堆大小错误   在unix/linux中工作的java中将unicode字符串转换为ASCII   java是否缺少正确对齐输出的值?   java Spring 3 MVC:动态表单中的onetomany(创建/更新时添加/删除)   java在接口中创建两个通用参数   lambda使用Java 8从嵌套列表中使用forEach查找项的替代方法是什么?   Java正则表达式匹配10位电话号码,中间有空格   linux将log4j外部化。使用命令行Java的属性文件   带有SSL的java简单RMI服务器   java无法为事务[…]打开JPA EntityManager无法获取驱动程序类“null”和URL“null”的连接   Android设备上的java Oauth Foursquare   for循环的ImageButton名称的java骰子模拟浓缩   java有没有简单的1d条形码阅读器?   如何在调用resultset后解决“无效字符串或缓冲区长度”。从java到访问mdb的getString()连接   在Java8中,是否可以使用JVM参数来控制何时(或在什么条件下)卸载类?