Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

create temporary files in python

import tempfile

# Creates a file and returns a tuple containing both the handle and the path.
handle, path = tempfile.mkstemp()
with open(handle, "w") as f:
    f.write("Hello, World!");
Comment

python temporary file

import tempfile
import os

# Creates a file and returns a tuple containing both the handle and the path.
handle, path = tempfile.mkstemp()

# full path of temp file
print("Temp file path:", path)
# output example /var/folders/mk/2ghcw18s6xx2fxjv_ybk7x640000gn/T/tmp465djfe4

# write to temp file
with open(handle, "w") as f:
    f.write("Hello, World!")


# read from temp file
with open(path, "r") as f:
    print(f.readlines())
# output ['Hello, World!']

# delete the temporary file
os.unlink(path)
Comment

PREVIOUS NEXT
Code Example
Python :: draw bounding box matplotlib 
Python :: how to add list numbers in python 
Python :: upload file to s3 
Python :: input code for python 
Python :: get column index pandas 
Python :: word2vec 
Python :: ValueError: Shapes (None, 1) and (None, 3) are incompatible 
Python :: pandas como quitar comillas simples de una columna 
Python :: how to print out even index in python 
Python :: download images off unsplash python 
Python :: axis labels python 
Python :: python convert 
Python :: how to make a bill in python 
Python :: readlines 
Python :: dda line drawing algorithm 
Python :: wifite2 
Python :: python string replace variable 
Python :: mongodb in python 
Python :: f readlines python not working 
Python :: python sort an array 
Python :: chi square test contingency table python 
Python :: # enumerate 
Python :: how to union value without the same value in numpy 
Python :: how to get the length of a string in python 
Python :: file storage django 
Python :: request session python 
Python :: get files in directory 
Python :: python library for downsampling a photo 
Python :: upload bytes to s3 python 
Python :: python ceiling division 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =