Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

This module generates temporary directories

Project Description

Function parameters:

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

By default temporary directory will be deleted when function it is closed.

Example 1:

The name property returns the name of a temporary directory.

import os
from sptempdir import TemporaryDirectory

with TemporaryDirectory(prefix="prefbegin_", suffix="_suffend") as temp:
    print('temp.name:', temp.name)  # retrieve the name temporary directory
    print('Inside:', os.path.exists(temp.name))

print('Outside:', os.path.exists(temp.name))

Terminal output:

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

Example 2:

import os
from sptempdir import TemporaryDirectory

temp = TemporaryDirectory()
print('temp.name:', temp.name)  # retrieve the name temporary directory
print('Tempdir exists:', os.path.exists(temp.name))

temp.remove()  # manually remove temporary directory
print('Tempdir exists:', os.path.exists(temp.name))

Terminal output:

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

Example 3:

If the delete parameter is delete=False, the temp directory is not deleted.

import os
from sptempdir import TemporaryDirectory

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

temp.remove()  # manually remove temporary directory
print('Tempdir exists:', os.path.exists(temp.name))

Terminal output:

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

Example 4:

Specific dir where you want to create temporary directory.

from sptempdir import TemporaryDirectory

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

Terminal output:

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

Installation:

pip install sptempdir

License:

BSD

(SP)TEMPDIR = ( Simple Python ) TEMPDIR


Release History

Release History

This version
History Node

0.1.5

History Node

0.1.4

History Node

0.1.3

History Node

0.1.2

History Node

0.1.2a0

History Node

0.1.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
sptempdir-0.1.5.tar.gz (3.3 kB) Copy SHA256 Checksum SHA256 Source Apr 18, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting