Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View hngkr's full-sized avatar

Henning Kristensen hngkr

  • Aarhus, Denmark
View GitHub Profile
@hngkr
hngkr / tempfile-contextmanager.py
Created July 12, 2019 22:01
tempfile.TemporaryDirectory example
with tempfile.TemporaryDirectory() as workdir:
project_dirname = "project"
project_dir = os.path.join(workdir, project_dirname)
os.mkdir(project_dir)
# do esoteric work within that temporary workdir
@hngkr
hngkr / NamedTemporaryFile_example.py
Created July 12, 2019 22:12
NamedTemporaryFile example
import boto3
import tempfile
s3_bucket = "..."
s3_path = "..."
s3 = boto3.resource('s3', region_name='eu-west-1')
with tempfile.NamedTemporaryFile() as downloaded_file:
s3.Object(s3_bucket, s3_path).download_file(downloaded_file.name)
# continue processing downloaded_file