开发者

saving to /home/user/Documents in different locales / languages

开发者 https://www.devze.com 2023-02-09 14:28 出处:网络
In my linux python app for Fedora I want to save开发者_运维技巧 user\'s work to /home/user/Documents/MyCoolApp/TheirGreatWork.txt

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

saving to /home/user/Documents in different locales / languages

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号