哪里是存储 Python 脚本的 Windows 配置文件的好地方/方法?

发布于 2024-09-02 11:45:31 字数 356 浏览 2 评论 0原文

我正在处理一个需要配置文件的脚本/程序(我正在使用 ConfigParser )。在 Linux 上,我将默认使用 os.getenv('HOME') 函数将这些变量存储在 ~/.myscript 中。

在 Windows 中,我知道我可以使用 os.getenv('USERPROFILE') 来查找用户的“主”目录,但是,保存一个隐藏目录是个好主意吗?那样的文件(即名称为 .myscript)?

显然,我不使用 Windows,但我想为那些使用 Windows 的人提供一些明智的建议。

Windows 上是否有存储这些配置变量的标准位置/方法?

I have a script/program I am working on that requires a configuration file (I am using ConfigParser). On linux, I will default to store these variables in ~/.myscript using the os.getenv('HOME') function.

With Windows, I know I can use os.getenv('USERPROFILE') to find the User's "home" directory, however, is it a good idea to save a hidden file that way (ie, with the name .myscript)?

I don't use Windows, obviously, but wanted to be smart about it for those who do.

Is there a standard place/way to store these config variables on Windows?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泛泛之交 2024-09-09 11:45:31
os.environ['AppData']

通常会在其中创建一个包含您的组织名称的文件夹,并将所有文件放入其中。无需“隐藏”文件,文件名开头的 . 在 Windows 中无效。

或者将设置放入注册表

os.environ['AppData']

It's usual to create a folder inside with your organisation name and put any files inside that. There's no need to ‘hide’ the files, and . at the start of a filename isn't valid in Windows.

Or put the settings in the registry.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文