python 2.7.12 on Linux behaving differently than on Windows

Michael Torrie torriem at gmail.com
Tue Dec 6 10:44:57 EST 2016


On 12/06/2016 04:43 AM, BartC wrote:
>> 	Read the Python documentation for argparse
> 
> I just tried it, but it was too complex for me to set it up so as to 
> discover with it did with * arguments.
> 
>> 	Again, start with argparse... Any command line argument that is left
>> after it has parsed the line can likely be considered a "filename".
> 
> Only at the end?

No, that's not what he said. After arguments have been parsed out and
dealt with, whatever is left can be retrieved as the parameters (whether
those are filenames or urls or something.  All remaining parameters.
Wherever they appeared.  Some argument parsers do require all arguments
to be first on the command line.  argparse is not one of them.  BSD
tools typically do want args first.  And actually a lot of windows
applications are extremely picky about where the arguments come vs the
"filespec" parameters.

>   And to
>> handle the difference between Windows and UNIX you'd likely need something
>> like:
>>
>> for aParm in remainingArguments:
>> 	for aFile in glob.glob(aParm):
>> 		do something with the file
> 
> Suppose any argument contains * or ?, isn't a filename, but happens to 
> match some files in the current directory. AFAICS it will still screw up.

Precisely! And you can bet there is probably more than one Windows
program out there that incorrectly makes this assumption and does the
wrong thing.  Or the opposite is true and there are programs that expect
no globs and can do nothing with them.  And for such a buggy program
there's not a darn thing the user can do to escape the glob or otherwise
tell the program it's not a glob.

That's why I would far rather place globbing in control of the shell
where a user can properly deal with it, escape it, or otherwise disable
it when necessary.

Yes shell expansion has it's gotchas.  But those can all be learned,
whereas it's much harder to learn and remember all the gotchas and bugs
of many individual applications' unique ways of dealing with globs. I'd
rather deal with shells.



More information about the Python-list mailing list