python 2.7.12 on Linux behaving differently than on Windows

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Dec 7 00:15:32 EST 2016


On Wednesday 07 December 2016 12:55, BartC wrote:

> But even Linux's 128KB will fill if someone wanted a command line that
> listed 20,000 files individually. But it would be spectacularly bad use
> of a command line interface which was designed for humans.

That's EXACTLY the point of having the shell do globbing.

I want to pass a whole lot of file names to some obscure command. I don't 
remember how that command deals with metacharacters, but it doesn't matter: I 
just say 

    command fooba?.jpg {here,there}/*.jpg  another/place/*.{png,jpg} [a-z]/IMG*

and the shell expands the metacharacters ? {...} * [...] regardless of how much 
smarts the command itself has.

There are thousands of programs I might use, and they may implement who knows 
how many different globbing rules:

- some might support * and ? but not {...}
- some might support SQL-like % and _
- some might insist on regular expressions instead of globs
- some might support the full set of globbing metacharacters, but have bugs
- some might not support any metacharacters
- some might not support ** for recursive wildcards


Don't say "they'll all call a library to do it for them", because even if such 
a library exists, its not necessarily the case that everyone will use it, or 
*want* to use it. There are always those who insist on doing things their own 
way, for their own reasons:

https://www.xkcd.com/1168/

https://explainxkcd.com/wiki/index.php/1168:_tar


I can't easily know in advance what globbing rules I can use for a particular 
command, but I can know what rules my shell uses, and now *all* commands 
support the same, whether they know it or not.




-- 
Steven
"Ever since I learned about confirmation bias, I've been seeing 
it everywhere." - Jon Ronson




More information about the Python-list mailing list