Lance Gamet wrote:
Lance Gamet wrote:
One way I've just started to use it to create a utility function to
return the location of the user data folder, depending on the operating
system:
import os, sys
def GetUserDataDire ctory():
dir = None
# WINDOWS
if os.name == "nt":
# Try env APPDATA or USERPROFILE or HOMEDRIVE/HOMEPATH
if "APPDATA" in os.environ:
dir = os.environ["APPDATA"]
if ((dir is None) or (not os.path.isdir(d ir))) and ("USERPROFIL E"
in os.environ):
dir = os.environ["USERPROFIL E"]
if os.path.isdir(o s.path.join(dir , "Applicatio n Data")):
dir = os.path.join(di r, "Applicatio n Data"))
if ((dir is None) or (not os.path.isdir(d ir))) and ("HOMEDRIVE"
in os.environ) and ("HOMEPATH" in os.environ):
dir = os.environ["HOMEDRIVE"] + os.environ["HOMEPATH"]
if os.path.isdir(o s.path.join(dir , "Applicatio n Data")):
dir = os.path.join(di r, "Applicatio n Data"))
if (dir is None) or (not os.path.isdir(d ir))
dir = os.path.expandu ser("~")
# One windows, add vendor and app name
dir = os.path.join(di r, "vendor", "app")
# Mac
elif os.name == "mac": # ?? may not be entirely correct
dir = os.path.expandu ser("~")
dir = os.path.join(di r, "Library", "Applicatio n Support")
dir = os.path.join(di r, "vendor", "app")
# Unix/Linux/all others
else:
dir = os.path.expandu ser("~")
dir = os.path.join(di r, ".app")
# Some applications include vendor
# dir = os.path.join(di r, ".vendor", "app")
return dir
Brian Vanderburg II
Hi, python beginner starting a new project here.
>
This project will store most of its actual data in a shared-database, but
I have a small amount of user specific data that I need to be stored like
configuration or preferences for example, the list of databases that the
program should connect to.
>
On Unix this might be a .file, on windows this could be in the registry,
or an ini file or an xml file in ProgramData or AppData or something.
>
Is there a pythony way to store such config data, perhaps there is
already a standard python package for such a purpose?
>
My app uses Qt, and Qt has its method of doing it (QSettings), but for
architectural reasons I don't want to use it.
>
Could sqlite be an option perhaps? I am still undecided if the ability
for the user to edit the file independently of the program is a good or
bad thing.
>
Thanks a lot.
Lance
--
>
>
This project will store most of its actual data in a shared-database, but
I have a small amount of user specific data that I need to be stored like
configuration or preferences for example, the list of databases that the
program should connect to.
>
On Unix this might be a .file, on windows this could be in the registry,
or an ini file or an xml file in ProgramData or AppData or something.
>
Is there a pythony way to store such config data, perhaps there is
already a standard python package for such a purpose?
>
My app uses Qt, and Qt has its method of doing it (QSettings), but for
architectural reasons I don't want to use it.
>
Could sqlite be an option perhaps? I am still undecided if the ability
for the user to edit the file independently of the program is a good or
bad thing.
>
Thanks a lot.
Lance
--
>
Hi, python beginner starting a new project here.
>
This project will store most of its actual data in a shared-database, but
I have a small amount of user specific data that I need to be stored like
configuration or preferences for example, the list of databases that the
program should connect to.
>
On Unix this might be a .file, on windows this could be in the registry,
or an ini file or an xml file in ProgramData or AppData or something.
>
Is there a pythony way to store such config data, perhaps there is
already a standard python package for such a purpose?
>
My app uses Qt, and Qt has its method of doing it (QSettings), but for
architectural reasons I don't want to use it.
>
Could sqlite be an option perhaps? I am still undecided if the ability
for the user to edit the file independently of the program is a good or
bad thing.
>
Thanks a lot.
Lance
--
>
>
This project will store most of its actual data in a shared-database, but
I have a small amount of user specific data that I need to be stored like
configuration or preferences for example, the list of databases that the
program should connect to.
>
On Unix this might be a .file, on windows this could be in the registry,
or an ini file or an xml file in ProgramData or AppData or something.
>
Is there a pythony way to store such config data, perhaps there is
already a standard python package for such a purpose?
>
My app uses Qt, and Qt has its method of doing it (QSettings), but for
architectural reasons I don't want to use it.
>
Could sqlite be an option perhaps? I am still undecided if the ability
for the user to edit the file independently of the program is a good or
bad thing.
>
Thanks a lot.
Lance
--
>
return the location of the user data folder, depending on the operating
system:
import os, sys
def GetUserDataDire ctory():
dir = None
# WINDOWS
if os.name == "nt":
# Try env APPDATA or USERPROFILE or HOMEDRIVE/HOMEPATH
if "APPDATA" in os.environ:
dir = os.environ["APPDATA"]
if ((dir is None) or (not os.path.isdir(d ir))) and ("USERPROFIL E"
in os.environ):
dir = os.environ["USERPROFIL E"]
if os.path.isdir(o s.path.join(dir , "Applicatio n Data")):
dir = os.path.join(di r, "Applicatio n Data"))
if ((dir is None) or (not os.path.isdir(d ir))) and ("HOMEDRIVE"
in os.environ) and ("HOMEPATH" in os.environ):
dir = os.environ["HOMEDRIVE"] + os.environ["HOMEPATH"]
if os.path.isdir(o s.path.join(dir , "Applicatio n Data")):
dir = os.path.join(di r, "Applicatio n Data"))
if (dir is None) or (not os.path.isdir(d ir))
dir = os.path.expandu ser("~")
# One windows, add vendor and app name
dir = os.path.join(di r, "vendor", "app")
# Mac
elif os.name == "mac": # ?? may not be entirely correct
dir = os.path.expandu ser("~")
dir = os.path.join(di r, "Library", "Applicatio n Support")
dir = os.path.join(di r, "vendor", "app")
# Unix/Linux/all others
else:
dir = os.path.expandu ser("~")
dir = os.path.join(di r, ".app")
# Some applications include vendor
# dir = os.path.join(di r, ".vendor", "app")
return dir
Brian Vanderburg II