Nobody wrote:
On Tue, 17 Nov 2009 11:47:46 -0800, Gerry wrote:

How about this:

lastarg = " ".join(sys.argv[2:])

What about it?

IOW, why would you want to do that?


Like many tricks, it'd work if several conditions applied:

1) there's exactly two arguments expected on the command line
2) you know that the second argument may have one or more spaces in it, but not consecutively, and no quotes immediately after any such space. 3) you don't mind fooling the user by making *most* cases work, so he's not trained for the general case.

This one reminds me of CreateProcess() in Windows, which parses for the program by looking for each space, and seeing if there's an appropriate EXE file there. So if you have stuff installed in "C:\Program Files\My Dir\yyy" directory, you can be blindsided by someone creating a program in the root called c:\program.exe, or "c:\Program Files\My.exe" CreateProcess() keeps trying till one works, instead of immediately giving a diagnosable error.

That was my (correct) diagnosis of an actual customer problem, referred to me by tech support. Customer described error message, and I studied what could cause it. Called back and asked whether there was a program.exe in the root directory. Told him to (temporarily) remove it. Problem vanished. Customer astounded how we could know about its existence. Of course it was really a bug in one of the products at my company, where quotes weren't used. Not usually needed, because of this "flexibility" on the part of CreateProcess()

DaveA
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to