python uses temporary files

# Demand 
# after a project, we collect data from sensors, not 1G data collection, data analysis done, save only the final results 
# such a large temporary files if resident in memory, will consume a large amount of memory resources, we may be used to store temporary files (external memory) 
# automatically delete the temporary file name does not need, and closes after: advantages 

# solution: TempporaryFile and NameTempporaryFile under standard library using the tempfile 
from the tempfile Import TemporaryFile, NamedTemporaryFile 

F = TemporaryFile ()          # generated examples of temporary files, temporary files do not appear in the disk directory in 
the n-NamedTemporaryFile = (delete = True)     # generate temporary files instance, temporary files will appear in the disk directory delete delete True False saved after the delete parameter specifies the file 
f.write ( " ABCs " * 100000 ) 
f.seek (0)      # the file pointer at the head 
f.read (100)  # Before reading the file read only file 100

 

Guess you like

Origin www.cnblogs.com/jum-bolg/p/10963322.html