Search code examples
pythonjsonfilepyinstallersoftware-packaging

What are the file places after you package a python program?


I am wanting to package my program that uses over files to store user data locally, but I don't know what directory I should put in all the json.load and json.dump. So right now, I have the directory equal to json.dump(somelist,open('/home/username/filename','w')) but when someone downloads it, the program won't work since it is a different directory. I am trying to PyInstaller but maybe PyInstaller will do it for me. I was just wondering and I couldn't find anything on google but if there is something, please link it to me. Thanks in advance!!


Solution

  • Use the following to get the user's home directory:

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