msg281636 - (view) |
Author: George Fischhof (georgefischhof) |
Date: 2016-11-24 15:01 |
Hi There, I started to use ConfigParser, and found that it has no write to file_name option, but xml paarser (ElementTree) has. This way ConfigParser works different than xml parsers, as when I use elementtree.write it will create a file with full and valid xml content. But ConfigParser is "able" ;-) to create file with invalid content (for example (this was my findings) creates duplicated sections. Because the handling of the file is in the user's hand. So it would be good for ConfigParser to handle file writing and the user!s code would became simplier: Feature request: ConfigParser should be able to write config to a given filename, not only into file object. (Like xml parser) Kind regards, George Fischhof |
|
|
msg313597 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2018-03-11 13:14 |
What is a problem with writing two lines of code? with open(...) as f: config.write(f) If combine ConfigParser.write() with builtin open() you will need to add support of encoding, errors, buffering, newline, and other arguments supported by open(). And don't forgot to update this method after adding new parameters to open(). I'm -1. Not every two lines of code deserve including as a function in the stdlib. This will clutter the user interface, complicate the implementation, and add the burden to core developers for maintaining this code. |
|
|
msg313598 - (view) |
Author: Terry J. Reedy (terry.reedy) *  |
Date: 2018-03-11 13:52 |
George, your third sentence is missing a closing ')' somewhere. In the first part, I believe you meant that the user is able to create a bad file by directly writing other content or calling cf.write more than once. I don't get the part about duplicated sections. I was otherwise +-0 about the feature until Serhiy articulated the negatives. I am now more inclined to close this. I just reviewed the PR, and the added complications in the test mirror the added complication in the code. With the patch as is, we should document that if a filename is passed, it would be opened with default args other than the mode. There are other filename or file APIs, but that does not mean that they are without problems. I suspect that at least some date to times before the addition of with statements. |
|
|
msg313601 - (view) |
Author: Berker Peksag (berker.peksag) *  |
Date: 2018-03-11 15:32 |
I agree with Serhiy and Terry. Also, PR 5999 does not accept pathlib.Path() objects at the moment. This and Serhiy's following comment are good examples of why it shouldn't be added to the standard library in my opinion: > If combine ConfigParser.write() with builtin open() you will need to > add support of encoding, errors, buffering, newline, and other > arguments supported by open(). And don't forgot to update this method > after adding new parameters to open(). |
|
|
msg313602 - (view) |
Author: Matej Cepl (mcepl) * |
Date: 2018-03-11 15:42 |
OK, Serhiy you have the point: it was just a good exercise for me, but the benefit is doubtful. Could somebody close this ticket then? |
|
|