python 2.7.12 on Linux behaving differently than on Windows

Chris Angelico rosuav at gmail.com
Sun Dec 4 17:58:27 EST 2016


On Mon, Dec 5, 2016 at 9:19 AM, BartC <bc at freeuk.com> wrote:
> Command parameters /do/ behave differently between Windows and Linux, for
> example try writing *.* as that third parameter.
>
> In Windows, it will print *.*.
>
> In Linux, if you have 273 files in the current directory, if will print the
> name of the first, and there will be /272 further command parameters/, each
> the name of a file. (I couldn't believe this when I found out; one of my
> directories recently had 3.4 million files in it, I don't really want *.*
> expanded to 3.4m arguments. Here, the fix is again to use double quotes:
> "*.*". But what if the user doesn't do that?)

Technically this isn't a Win/Lin difference, but a shell difference.
The behaviours you're referring to are common to many Unix shells
(including bash, the most commonly used shell on typical Linux
systems). If you want a glob to be processed by the application,
rather than the shell, you have to escape it with quotes or
backslashes. Most of the time, it's easiest to write your app to
accept multiple file names, and let the shell expand them - there's a
lot more flexibility than just * and ?, and every program behaves the
same way, because it's the same shell parsing them all.

ChrisA


More information about the Python-list mailing list