Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 ?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.