How to store properties

Cecil Westerhof Cecil at decebal.nl
Wed Feb 8 07:46:37 EST 2017


On Wednesday  8 Feb 2017 13:11 CET, Peter Heitzer wrote:

> Cecil Westerhof <Cecil at decebal.nl> wrote:
>> In Java you (can) use a properties file store configuration. What
>> is the best way to do something like that in Python? I saw
>> ConfigParser, but have the feeling that it is not really used.
>> Would a JSON file be a good idea?
>
> If you only want to read the configuration, just use an ordinary 
> file you import. For example config.py contains the lines:
> username=myuser
> server=myserver
> password=secret
>
> In your script:
>
> import config
>
> Now you can referenc all the variables via config.<name>, e.g.
> config.username

That I know, but it is a security risk.


> Another method would be a dictionary for your config. You could
> pickle and unpickle it.

Is pickle not discouraged? Better to use a JSON file I think.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof



More information about the Python-list mailing list