[Python-Dev] Alternate notation for global variable assignments
Zack Weinberg
zack at codesourcery.com
Mon Oct 27 17:55:04 EST 2003
"Steve Holden" <sholden at holdenweb.com> writes:
>>
>> :var = value # var in module scope
>> :scope:var = value # var in named enclosing scope
>>
>> An advantage of this notation is that it can be used anywhere, not
>> just in an assignment. This has primary value for people reading the
>> code -- if you have a fairly large class method that uses a module
>> variable (not by assigning it) somewhere in the middle, writing it
>> :var means the reader knows to go look for the assignment way up top.
>> This should obviously be optional, to preserve backward compatibility.
>>
> However, its use in such expressions as
>
> sublist = lst[:var]
>
> would lead to substantial ambiguities, right?
I suppose it would. Unfortunately, there's no other punctuation mark
that can really be used for the purpose -- I think both $ and @
(suggested elsewhere in response to a similar proposal) have
too many countervailing connotations. Witness e.g. the suggestion
last week that $ become magic in string % dict notation.
Py-in-the-sky suggestion: make the slice separator character be ;
instead of :. (Half serious.)
Somewhat warty suggestion: take lst[:var] to be a slice, but
lst[(:var)] to be a global variable reference. And lst[:(:var)] to be
a slice on a global, etc. etc.
Better ideas solicited.
zw
More information about the Python-Dev
mailing list