4 ms·
Hi, I had a quick look and here are my remarks: - with the [six] library, there's no need to maintain two versions - parsing script args yourself isn't neces
by LockAndLol 7y ago
Hi,
I had a quick look and here are my remarks:
- with the [six] library, there's no need to maintain two versions
- parsing script args yourself isn't necessary either thanks to tools like, [argparse] (in the stdlib), [click], [docopt]
- not quite sure why you use the RawCongigParser, but it seems like you're modifying the behavior thereof. It might be advisable to subclass it instead
- a little documentation wouldn't hurt
- it's not entirely clear why the code is doing what it's doing
- not sure what the goal of this is
Haven't run it through a linter, but I like the descriptive variable names and methods and the spacing. The lack of a argument parser has led you to convoluted code however: 5 levels of ifs aren't easy to read.
[argparse]: https://docs.python.org/3/library/argparse.html https://docs.python.org/3/library/argparse.html
[click]: https://pypi.org/project/click8/ https://pypi.org/project/click8/
[docopt]: https://pypi.org/project/docopt/ https://pypi.org/project/docopt/
[six]: https://pypi.org/project/six/ https://pypi.org/project/six/
- stephenr 7y agoThanks for taking a look! To answer some of your questions: the goal of this (the concept rather than just this python implementation) is to read keys and values out of 'ini' formatted files from shell, by detecting which other languages can run on the machine (so far, python2, python3, php with DBA support, and php without DBA support), but Python's idea of what constitutes a valid 'ini' file is more restrictive than other languages, in that it doesn't allow for values before the first section heading (the parts in square brackets). So that's why it inserts a 'fake' section header and passes the StringIO object rather than just the file itself. I'll look into argparse - being in the stdlib is a must - the only reason this (or it's counterpart in php) exists is because so far I've found no practical/reliable way to reliably read/write ini files via pure shell. Having to package up extra libs, or require a non-standard lib would defeat the purpose. I wonder if that's going to be the situation with 'six' - is it a runtime library, or more of a 'build' tool, to transpile from 3 to 2? I honestly don't remember why I ended up using the RawConfigParser rather than just ConfigParser - maybe one of the options for ConfigParser (e.g. disabling interpolation), wasn't available in earlier 3.x releases. I'll try this again when looking at the above points. Thanks for your input, it's very much appreciated!
- LockAndLol 7y ago> I wonder if that's going to be the situation with 'six' - is it a runtime library, or more of a 'build' tool, to transpile from 3 to 2? It's a runtime library. [2to3] is in the stdlib and transpiles. > To answer some of your questions: That whole paragraph could be put at the top of the file in a triple-quote. It explains what the file is for pretty nicely. If you end up using argparse it could be in the description :) I'm glad I could help somehow. Have a nice easter! [2to3]: https://docs.python.org/3/library/2to3.html https://docs.python.org/3/library/2to3.html