[Python-3000] Move argv[0]? (Re: Unicode and OS strings)
Larry Hastings
larry at hastings.org
Sun Sep 16 14:01:52 CEST 2007
Guido van Rossum wrote:
> On 9/15/07, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>
>> Changing the existing behaviour of argv would probably
>> be too disruptive, so how about relegating argv to a
>> low-level detail and providing something else for
>> everyday use that omits argv[0]?
>>
>> sys.arguments would sound quite nice for that.
> This sounds awfully close to bikeshedding. Change too many details
> like this and you cause death by a 1000 pinpricks for existing apps.
> sys.argv[0] *does* get used (though arguably rarely in the same way as
> sys.argv[1:]).
+0.5 on Greg Ewing's proposal.
argv[0] has little in common with argv[1:]; why should the user have to
differentiate them? I see this as yet one more messy detail of the OS
that Python could hide for me. Looking at it with fresh eyes, I think
for a in sys.arguments:
is a lot prettier than
for a in sys.argv[1:]:
After all: what's that 1: doing there? Why the magic number? Why does
argv have the script name in [0], anyway? None of my other
functions/members are forced to take themselves as their first argument.
Taking it to its logical conclusion, I further propose:
sys.raw_argv -- the original bytes as they came in from from the OS
sys.argv -- raw_argv converted into (unicode) strings, not expected
to be used by users
sys.arguments -- sys.argv[1:]
sys.script_path -- sys.argv[0]
sys.split_argv -- callable that takes an argv-style array (strings,
not bytes) and assigns it into argv, arguments, and script_path, slicing
as appropriate
Yes, the format of argv has thirty years of history; yes I don't really
expect this discussion to get anywhere. But I hate having arbitrary
idioms in Python, and I wanted to cast my vote into the swirling void
before this idea totally died.
If nothing else, at least we could fix the proviso for argv[0]: "(it is
operating system dependent whether this is a full pathname or not)."
How about we always ensure it is an absolute path?
My "there's only one way to do it" reflex is fighting it out with my
"beautiful is better than ugly" reflex,
/larry/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20070916/d659a8f2/attachment.htm
More information about the Python-3000
mailing list