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 :: python continue vs pass 
Python :: dask show progress bar 
Python :: python initialize dictionary with lists 
Python :: print all alphabets from a to z in python 
Python :: random string generator python 
Python :: add header to table in pandas 
Python :: linux command on python 
Python :: b1-motion tkinter 
Python :: save timestamp python 
Python :: python enum declare 
Python :: while loop countdown python 
Python :: python nmap 
Python :: split list in 3 part 
Python :: ImportError: No module named pip --Windows 
Python :: Finding the Variance and Standard Deviation of a list of numbers in Python 
Python :: python udp receive 
Python :: python snake game 
Python :: uninstall poetry 
Python :: pandas string does not contain 
Python :: make coordinate cyclic in python 
Python :: import fashion mnist keras 
Python :: pandas dataframe column to datetime 
Python :: python backward difference 
Python :: how to find the multiples of a number in python 
Python :: write file with python 
Python :: jupyter notebook play audio 
Python :: python convert remove spaces from beginning of string 
Python :: python config file 
Python :: add something to list python 
Python :: limpiar consola en python 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =