3

I am using the latest Anaconda Python distribution and I wonder how can I tell Python to unzip/store all the temporary output to a specific folder (instead of the /tmp directory).

Any ideas? Thanks!

ℕʘʘḆḽḘ
  • 18,566
  • 34
  • 128
  • 235
  • Do the [tempdir or tempfile](https://docs.python.org/3/library/tempfile.html) fit your needs? – ndclt Dec 29 '19 at 19:34
  • what I need is making sure whenever Python writes some temporary output somewhere, it is on a directory I defined (say `/mydrive/alternativeTMP`). Space is super limited in `tmp` and I need to avoid it – ℕʘʘḆḽḘ Dec 29 '19 at 19:35
  • which actions are writing to `/tmp`? – gold_cy Dec 29 '19 at 19:36
  • well I guess opening a `csv.gz` file, or decompressing some archive? – ℕʘʘḆḽḘ Dec 29 '19 at 19:37
  • I don't believe Python explicitly has the `-j` flag like `unzip` does in bash, that is what you are looking for correct? – gold_cy Dec 29 '19 at 19:43
  • thanks for helping out. no, I am looking for the R equivalent of setting up a `tmp` dir in Python. For instance, opening a compressed csv with Pandas `read_csv('myfile.csv.gz')` will necessarily decompress the file somewhere. I want to control where this is done. – ℕʘʘḆḽḘ Dec 29 '19 at 19:46
  • Is mounting /tmp on a different volume out of the question? – stolenmoment Dec 29 '19 at 19:53
  • 1
    I am not sure if this is possible to do in pure python – gold_cy Dec 29 '19 at 19:55

1 Answers1

4

I found something interesting in the tempfile page. The function gettempdir gets the temporary folder from the following environment variable:

  • The directory named by the TMPDIR environment variable.
  • The directory named by the TEMP environment variable.
  • The directory named by the TMP environment variable.
  • A platform-specific location:
    1. On Windows, the directories C:\TEMP, C:\TMP, \TEMP, and \TMP, in that order.
    2. On all other platforms, the directories /tmp, /var/tmp, and /usr/tmp, in that order.
  • As a last resort, the current working directory.

Maybe you can overwrite one of this variable.

ndclt
  • 2,590
  • 2
  • 12
  • 26