【问题标题】:What are the file places after you package a python program?打包python程序后的文件位置是什么?
【发布时间】:2014-08-16 00:27:11
【问题描述】:

我想打包我的程序,该程序使用 over 文件在本地存储用户数据,但我不知道应该将所有 json.loadjson.dump 放在哪个目录中。所以现在,我的目录等于json.dump(somelist,open('/home/username/filename','w')),但是当有人下载​​它时,程序将无法运行,因为它是一个不同的目录。我正在尝试 PyInstaller,但也许 PyInstaller 会为我做这件事。我只是想知道,我在谷歌上找不到任何东西,但如果有什么东西,请将它链接到我。提前致谢!!

【问题讨论】:

    标签: python json file pyinstaller software-packaging


    【解决方案1】:

    使用以下命令获取用户的主目录:

    from os.path import expanduser
    home = expanduser("~")
    with open(os.path.join(home, 'file'), 'w') as sr:
        json.dump(somelist, sr)
    

    【讨论】:

      猜你喜欢
      • 2013-08-28
      • 2021-06-20
      • 1970-01-01
      • 1970-01-01
      • 2010-10-31
      • 2021-10-15
      • 2010-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多