Reputation: 29892
I have a small Python program, which uses a Google Maps API secret key. I'm getting ready to check-in my code, and I don't want to include the secret key in SVN.
In the canonical PHP app you put secret keys, database passwords, and other app specific config in LocalSettings.php. Is there a similar file/location which Python programmers expect to find and modify?
Upvotes: 3
Views: 3735
Reputation: 8119
Any path can reference the user's home directory in a cross-platform way by expanding the common ~ (tilde) with os.path.expanduser()
, like so:
appdir = os.path.join(os.path.expanduser('~'), '.myapp')
Upvotes: 1
Reputation: 391952
A user must configure their own secret key. A configuration file is the perfect place to keep this information.
You several choices for configuration files.
Use ConfigParser
to parse a config file.
Use a simple Python module as the configuration file. You can simply execfile
to load values from that file.
Invent your own configuration file notation and parse that.
Upvotes: 4
Reputation: 99415
No, there's no standard location - on Windows, it's usually in the directory os.path.join(os.environ['APPDATA'], 'appname')
and on Unix it's usually os.path.join(os.environ['HOME'], '.appname')
.
Upvotes: 3