Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - Where should a library store temporary files?

I'm writing a Python library which needs to cache remote data on the local machine.

I would like to prevent the library from polluting the OS and placing temp files where they don't belong. To use OS default temp folders seems a bit long winded as I would like to use one OS-Independent way of doing this.

Would storing cached files within the package folder work? Does the Python installation have a folder for temp files?

Help would be great! :)

like image 833
RadiantHex Avatar asked Jul 10 '26 00:07

RadiantHex


2 Answers

Consider using tempfile, see http://docs.python.org/library/tempfile.html

like image 61
qiao Avatar answered Jul 13 '26 16:07

qiao


The default answer is to use tempfile; if you are using some other cross-platform toolkit, there might be other abstracted ways of achieving the same, for example in PyQt/PySide you have QtCore.QTemporaryFile.

like image 22
Giacomo Lacava Avatar answered Jul 13 '26 14:07

Giacomo Lacava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!