4 ms·
I wrote a pipe-objects-instead-of-strings shell: https://marceltheshell.org https://marceltheshell.org. Not piping strings avoids this issue completely. Marcel
by geophile 2y ago
I wrote a pipe-objects-instead-of-strings shell: https://marceltheshell.org https://marceltheshell.org.
Not piping strings avoids this issue completely. Marcel’s ls produces a stream of File objects, which can be processed without worrying about whitespace, EOL, etc.
In general, this approach avoids parsing the output of any command. You always get a stream of Python values.
- fooker 2y ago> In general, this approach avoids parsing the output of any command. Somewhere, there has to be validation phases. Just because you have objects, doesn't mean they are well formed. https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/ https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-va... It turns out proper validation is way harder than parsing. There is a reason text based interfaces and formats are so pervasive.
- geophile 2y agoAs long as Python does the right thing with globs, there is really no room for marcel to get it wrong. Not sure what additional validation you are thinking of.
- fooker 2y agoSuppose you store the result somewhere and then want to use it afterwards. How do you check if they are still valid files?
- geophile 2y agoThe File object encapsulates a path. If you use it, e.g. to read contents, and the file doesn't exist, then it will fail with an appropriate error message. Files come and go. References to them go stale. Every user and tool deals with this. This isn't a "validation" issue.