2

I am developing an app for the Ubuntu App Showdown 2012, say "myapp". It needs to download files from the web, store them temporarily and then read them. Where should I save those files ? Now I do it in /tmp/myapp/, so this path is "hard coded" in my code.

Would the answer to my question be changed if I also need to modify/write into those temporary files ?

1 Answer 1

4

I reckon you want to use the xdg module - in fact, I think this is suggested in at least one of the app showdown workshops.

The xdg module provides a means to get a base path for where certain files should be stored.

So, for temporary files, ~/.cache seems like a good bet.

http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html

$XDG_CACHE_HOME defines the base directory relative to which user specific non-essential data files should be stored. If $XDG_CACHE_HOME is either not set or empty, a default equal to $HOME/.cache should be used.

Example:

import xdg.BaseDirectory
import os

temp_path = os.path.join(xdg.BaseDirectory.xdg_cache_home, 'app_name', 'downloads')
print temp_path

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .