0

I'm writing a python code that will store data temporarily. In a unix like system I know of \tmp directory but can't figure out how to that for windows.

Sample Code:

import os

if os.name == 'nt':
    temp_directory = ''
elif os.name == 'posix':
    temp_directory = '/tmp/'

Do I use something like temp_directory = '%Temp%' ?

Edit:

The gettempdir() function from the tempfile module is what I was looking for.

listout
  • 97
  • 2
  • 8
  • Don't reinvent the wheel. Use [tempfile](https://docs.python.org/3/library/tempfile.html) – dawg May 14 '21 at 13:41

1 Answers1

0

It is better to use tempfile module https://docs.python.org/3/library/tempfile.html

DonKnacki
  • 427
  • 4
  • 11
  • 1
    This answer is very minimal and on the edge of a link-only answer. Either edit it to be more complete as described in [answer], or simply delete it as there are already many answers suggesting the same in the different duplicate targets around – Tomerikoo May 14 '21 at 13:55