If it's really temporary, follow larmans' advice and use mkdtemp
.
If it's some sort of semi-permanent cache that must survive reboots, then you should use the local application directory, as defined by your OS (%APPDATA%, ~/.local/ etc); some toolkits (e.g. Qt) provide functions to look that folder up in a cross-platform manner.
Edit: from Wikipedia:
- HOME (Unix-like) and USERPROFILE (Microsoft Windows) - indicate where
a user's home directory is located in the file system.
- HOME/{.AppName} (Unix-like) and APPDATA{DeveloperName\AppName}
(Microsoft Windows) - for storing application settings. Many open
source programs incorrectly use USERPROFILE for application settings
in Windows - USERPROFILE should only be used in dialogs that allow
user to choose between paths like Documents/Pictures/Downloads/Music,
for programmatic purposes use APPDATA (roaming), LOCALAPPDATA or
PROGRAMDATA (shared between users)
So you should look up os.environ['APPDATA']
or os.environ['HOME']
, depending on platform (see sys.platform
) and then append your app name, and then you can store there anything you want.
mydir = os.path.join( ".myAppName", "cache")
homeVar = 'HOME' # default for all *nix variants
if sys.platform == 'win32':
homeVar = 'APPDATA'
mydir = os.path.join( os.environ[homeVar], mydir)
user_cache_dir
vssite_data_dir
, which is more suitable for my case. – Kansu