Re: Most Pythonic way to store (small) configuration

2015-08-06 Thread Chris Angelico
On Thu, Aug 6, 2015 at 5:33 PM, Steven D'Aprano wrote: > On Thursday 06 August 2015 10:07, Chris Angelico wrote: > >> On Thu, Aug 6, 2015 at 9:43 AM, Tim Chase >> wrote: >>> Significant whitespace? Not usually simple (just stuck touching a >>> project where someone committed with tons of trailin

Re: Most Pythonic way to store (small) configuration

2015-08-06 Thread Steven D'Aprano
On Thursday 06 August 2015 10:07, Chris Angelico wrote: > On Thu, Aug 6, 2015 at 9:43 AM, Tim Chase > wrote: >> Significant whitespace? Not usually simple (just stuck touching a >> project where someone committed with tons of trailing whitespaces. >> grumble), so strip 'em off as if they're an e

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Rustom Mody
On Thursday, August 6, 2015 at 6:32:03 AM UTC+5:30, Rustom Mody wrote: > By contrast here is a more friendly error message (had put a comma where a > colon > required) > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python3.4/ast.py", line 46, in literal_eval >

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Rustom Mody
On Thursday, August 6, 2015 at 2:31:52 AM UTC+5:30, Tim Chase wrote: > On 2015-08-05 06:37, Rustom Mody wrote: > > > config = {} > > > with open('config.ini') as f: > > > for row in f: > > > row = row.strip() > > > if not row or row.startswith(('#', ';')): > > > continue

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Chris Angelico
On Thu, Aug 6, 2015 at 9:43 AM, Tim Chase wrote: > Significant whitespace? Not usually simple (just stuck touching a > project where someone committed with tons of trailing whitespaces. > grumble), so strip 'em off as if they're an error condition. I've > never had a config-file where I wanted l

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Tim Chase
On 2015-08-06 00:47, Marko Rauhamaa wrote: > > There's a certain simplicity to simply having key/value pairs > > separated by an "=" and then letting the application do whatever > > it needs/wants with those key/value strings. > > That trap has lured in a lot of wildlife. > > What to do with li

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Marko Rauhamaa
Tim Chase : > There's a certain simplicity to simply having key/value pairs > separated by an "=" and then letting the application do whatever it > needs/wants with those key/value strings. That trap has lured in a lot of wildlife. What to do with lists? Is whitespace significant? Case in poin

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Tim Chase
On 2015-08-05 06:37, Rustom Mody wrote: > > config = {} > > with open('config.ini') as f: > > for row in f: > > row = row.strip() > > if not row or row.startswith(('#', ';')): > > continue > > k, _, v = row.partition('=') > > config[k.strip().upper()] = v.lst

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Rustom Mody
On Wednesday, August 5, 2015 at 7:38:46 PM UTC+5:30, Steven D'Aprano wrote: > On Wed, 5 Aug 2015 11:46 pm, Rustom Mody wrote: > > > On Sunday, August 2, 2015 at 3:44:51 PM UTC+5:30, Cecil Westerhof wrote: > >> There are a lot of ways to store configuration information: > >> - conf file > >> - xml

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Steven D'Aprano
On Wed, 5 Aug 2015 11:46 pm, Rustom Mody wrote: > On Sunday, August 2, 2015 at 3:44:51 PM UTC+5:30, Cecil Westerhof wrote: >> There are a lot of ways to store configuration information: >> - conf file >> - xml file >> - database >> - json file >> - and possible a lot of other ways > > One that I

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Grant Edwards
On 2015-08-05, Michael Torrie wrote: > On 08/04/2015 01:59 PM, Ben Finney wrote: >> marco.naw...@colosso.nl writes: >> >>> Why not use Python files itself as configuration files? >> >> Because configuration data will be user-editable. (If it's not >> user-editable, that is itself a poor design c

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Rustom Mody
On Sunday, August 2, 2015 at 3:44:51 PM UTC+5:30, Cecil Westerhof wrote: > There are a lot of ways to store configuration information: > - conf file > - xml file > - database > - json file > - and possible a lot of other ways One that I dont think has been mentioned: ast.literal_eval -- https://m

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Rustom Mody
On Wednesday, August 5, 2015 at 6:58:01 PM UTC+5:30, Tim Chase wrote: > On 2015-08-02 12:11, Cecil Westerhof wrote: > > There are a lot of ways to store configuration information: > > - conf file > > - xml file > > - database > > - json file > > - and possible a lot of other ways > > > > I want to

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Tim Chase
On 2015-08-02 12:11, Cecil Westerhof wrote: > There are a lot of ways to store configuration information: > - conf file > - xml file > - database > - json file > - and possible a lot of other ways > > I want to write a Python program to display cleaned log files. I do > not think I need a lot of c

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Chris Angelico
On Wed, Aug 5, 2015 at 6:32 PM, Steven D'Aprano wrote: > My own personal feeling is that using code as config is a little > disquieting. It's a bit of a code smell. Do you really need that much power > just to allow people to set some configuration settings? Using a Turing > Complete programming l

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Steven D'Aprano
On Wednesday 05 August 2015 05:59, Ben Finney wrote: > marco.naw...@colosso.nl writes: > >> Why not use Python files itself as configuration files? > > Because configuration data will be user-editable. (If it's not > user-editable, that is itself a poor design choice.) > > If you allow executab

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread Lele Gaifax
Rustom Mody writes: > Does yaml have comments? Yes, the same syntax as Python's. ciao, lele. -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia. l...@metapensiero.it | -- Fortunato Depero, 1929.

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread Rustom Mody
On Wednesday, August 5, 2015 at 10:19:11 AM UTC+5:30, Michael Torrie wrote: > On 08/04/2015 08:44 PM, wrote: > > On Tue, Aug 4, 2015, at 21:32, Michael Torrie wrote: > >> In many of my projects I put basic config variables in a file like > >> config.py and import that in each module that needs it.

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread Michael Torrie
On 08/04/2015 08:19 PM, Cameron Simpson wrote: > So on the whole I am against python code as the config file format. Really, > who > needs a Turing complete configuration file? In Django's case, since you're intimately referring to certain classes and methods, particularly in the url mapping sec

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread Michael Torrie
On 08/04/2015 08:44 PM, random...@fastmail.us wrote: > On Tue, Aug 4, 2015, at 21:32, Michael Torrie wrote: >> In many of my projects I put basic config variables in a file like >> config.py and import that in each module that needs it. The config >> module doubles as a global namespace for sharin

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread random832
On Tue, Aug 4, 2015, at 21:32, Michael Torrie wrote: > In many of my projects I put basic config variables in a file like > config.py and import that in each module that needs it. The config > module doubles as a global namespace for sharing between modules as well. What about JSONP? That is, a f

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread Cameron Simpson
On 04Aug2015 19:32, Michael Torrie wrote: On 08/04/2015 01:59 PM, Ben Finney wrote: marco.naw...@colosso.nl writes: Why not use Python files itself as configuration files? Because configuration data will be user-editable. (If it's not user-editable, that is itself a poor design choice.) If

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread Michael Torrie
On 08/04/2015 01:59 PM, Ben Finney wrote: > marco.naw...@colosso.nl writes: > >> Why not use Python files itself as configuration files? > > Because configuration data will be user-editable. (If it's not > user-editable, that is itself a poor design choice.) > > If you allow executable code to b

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread Ben Finney
marco.naw...@colosso.nl writes: > Why not use Python files itself as configuration files? Because configuration data will be user-editable. (If it's not user-editable, that is itself a poor design choice.) If you allow executable code to be user-edited, that opens your program to arbitrary injec

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread marco . nawijn
On Tuesday, August 4, 2015 at 7:06:33 PM UTC+2, Irmen de Jong wrote: > On 4-8-2015 16:53, marco.naw...@colosso.nl wrote: > > Why not use Python files itself as configuration files? > > It could create a security risk if the config files are user-editable. > (it will make it easy to inject code int

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread Irmen de Jong
On 4-8-2015 16:53, marco.naw...@colosso.nl wrote: > Why not use Python files itself as configuration files? It could create a security risk if the config files are user-editable. (it will make it easy to inject code into your application) Irmen -- https://mail.python.org/mailman/listinfo/python

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread marco . nawijn
On Sunday, August 2, 2015 at 12:14:51 PM UTC+2, Cecil Westerhof wrote: > There are a lot of ways to store configuration information: > - conf file > - xml file > - database > - json file > - and possible a lot of other ways > > I want to write a Python program to display cleaned log files. I do >

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread Jean-Michel Pichavant
- Original Message - > From: "Cecil Westerhof" > To: python-list@python.org > Sent: Sunday, 2 August, 2015 12:11:28 PM > Subject: Most Pythonic way to store (small) configuration > > There are a lot of ways to store configuration information: > - conf

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread c.buhtz
Dear Cecil, I subscribed to late to answer to your top-post in that thread. I had the same topic for myself in the last months and tried a lot of things. In your situation I would prefere the INI-file format, too. But doen't user 'configparser' for that. As other fellows described it's a bad sol

Re: Most Pythonic way to store (small) configuration

2015-08-03 Thread Mark Lawrence
On 03/08/2015 14:38, Steven D'Aprano wrote: On Mon, 3 Aug 2015 02:02 pm, Dan Sommers wrote: Well, I have at least some non-zero chance of reading and writing JSON or XML by hand. Can the same be said for a sqlite database? Real programmers edit their SQL databases directly on the hard drive

Re: Most Pythonic way to store (small) configuration

2015-08-03 Thread Chris Angelico
On Mon, Aug 3, 2015 at 11:38 PM, Steven D'Aprano wrote: > On Mon, 3 Aug 2015 02:02 pm, Dan Sommers wrote: > >> Well, I have at least some non-zero chance of reading and writing JSON >> or XML by hand. Can the same be said for a sqlite database? > > > Real programmers edit their SQL databases dire

Re: Most Pythonic way to store (small) configuration

2015-08-03 Thread Steven D'Aprano
On Mon, 3 Aug 2015 02:02 pm, Dan Sommers wrote: > Well, I have at least some non-zero chance of reading and writing JSON > or XML by hand.  Can the same be said for a sqlite database? Real programmers edit their SQL databases directly on the hard drive platter using a magnetised needle and a ste

Re: Most Pythonic way to store (small) configuration

2015-08-02 Thread Dan Sommers
On Sun, 02 Aug 2015 16:11:14 -0500, Tim Chase wrote: > On 2015-08-02 21:54, Ben Finney wrote: >> So, both XML and JSON should be considered write-only, and produced >> only for consumption by a computer; they are a poor choice for >> presenting to a human. [snip] > I second Ben's thoughts again

Re: Most Pythonic way to store (small) configuration

2015-08-02 Thread Tim Chase
On 2015-08-02 21:54, Ben Finney wrote: > So, both XML and JSON should be considered write-only, and produced > only for consumption by a computer; they are a poor choice for > presenting to a human. > > The “INI” format as handled by the Python ‘configparser’ module is > what I would recommend for

Re: Most Pythonic way to store (small) configuration

2015-08-02 Thread Ben Finney
Cecil Westerhof writes: > On Sunday 2 Aug 2015 13:54 CEST, Ben Finney wrote: > > > So, both XML and JSON should be considered write-only, and produced > > only for consumption by a computer; they are a poor choice for > > presenting to a human. > > Well, I would use nested data. (A file will hav

Re: Most Pythonic way to store (small) configuration

2015-08-02 Thread Cameron Simpson
On 02Aug2015 18:51, Cecil Westerhof wrote: On Sunday 2 Aug 2015 13:54 CEST, Ben Finney wrote: Cecil Westerhof writes: Because of this I think a human readable file would be best. I agree with that criterion; in the absence of compelling reasons otherwise, human-readable and -editable text

Re: Most Pythonic way to store (small) configuration

2015-08-02 Thread Lele Gaifax
Cecil Westerhof writes: > Well, I would use nested data. (A file will have extra fields besides > the name.) That is why I was thinking about json. But I will look into > it. An alternative, very similar to JSON but with some good cherries picked from YAML is AXON, which is my preferite these da

Re: Most Pythonic way to store (small) configuration

2015-08-02 Thread Cecil Westerhof
On Sunday 2 Aug 2015 13:54 CEST, Ben Finney wrote: > Cecil Westerhof writes: > >> Because of this I think a human readable file would be best. > > I agree with that criterion; in the absence of compelling reasons > otherwise, human-readable and -editable text is a good default. > >> Personally I

Re: Most Pythonic way to store (small) configuration

2015-08-02 Thread Mark Lawrence
On 02/08/2015 12:54, Ben Finney wrote: Cecil Westerhof writes: Because of this I think a human readable file would be best. The “INI” format as handled by the Python ‘configparser’ module is what I would recommend for a simple flat configuration file. It is more intuitive to edit, and has a

Re: Most Pythonic way to store (small) configuration

2015-08-02 Thread Ben Finney
Cecil Westerhof writes: > Because of this I think a human readable file would be best. I agree with that criterion; in the absence of compelling reasons otherwise, human-readable and -editable text is a good default. > Personally I do not find XML very readable. So a conf or json file > looks t

Re: Most Pythonic way to store (small) configuration

2015-08-02 Thread Chris Angelico
On Sun, Aug 2, 2015 at 8:11 PM, Cecil Westerhof wrote: > Because of this I think a human readable file would be best. > Personally I do not find XML very readable. So a conf or json file > looks the most promising to me. And I would have a slight preference > for a json file. > > Any comments, tho

Most Pythonic way to store (small) configuration

2015-08-02 Thread Cecil Westerhof
There are a lot of ways to store configuration information: - conf file - xml file - database - json file - and possible a lot of other ways I want to write a Python program to display cleaned log files. I do not think I need a lot of configuration to be stored: - some things relating to the GUI -