saving to /home/user/Documents in different locales / languages
In my linux python app for Fedora I want to save开发者_运维技巧 user's work to /home/user/Documents/MyCoolApp/TheirGreatWork.txt
But I am not sure how to find the "Documents
" folder if the user is not using English as their default language.
What is the right way to determine the right path so that files go in their "Documents" folder.
EDIT
Here is a
which comes up if you change locales... showing how paths can get easily changed.I'd use the subprocess module to get the output of the command xdg-user-dir DOCUMENTS
. For example:
import subprocess
documents_dir = subprocess.check_output(["xdg-user-dir", "DOCUMENTS"])
print documents_dir # This is what you're looking for.
There is no right way as the user may have changed their locale, which (fortunately) does not rename the directory. If you want a fixed place for files managed by your app, use ~user/.MyCoolApp
or let the user specify the directory.
精彩评论