[Python-Dev] Set the namespace free! (original) (raw)

Jesse Noller jnoller at gmail.com
Thu Jul 22 16:41:39 CEST 2010


On Thu, Jul 22, 2010 at 10:04 AM, Bartosz Tarnowski <bartosz-tarnowski at zlotniki.pl> wrote:

Hello, guys. Python has more and more reserved words over time. It becomes quite annoying, since you can not use variables and attributes of such names. Suppose I want to make an XML parser that reads a document and returns an object with attributes corresponding to XML element attributes:

elem = parsexml("") print elem.param boo What should I do then, when the attribute is a reserver word? I could use trailing underscore, but this is quite ugly and introduces ambiguity. elem = parsexml("") print elem.for #????? elem = parsexml("") print elem.for #?????_ My proposal: let's make a syntax change. Let all reserved words be preceded with some symbol, i.e. "!" (exclamation mark). This goes also for standard library global identifiers. !for boo in foo:  !if boo is !None:  !print(hoo)  !else:  !return !sorted(woo) This would allow the user to declare any identifier with any name: for = with(return) + try What do you think of it? It is a major change, but I think Python needs it. -- haael

I'm not a fan of this - I'd much prefer[1] that we use the exclamation point to determine scope:

foobar - local !foobar - one up !!foobar - higher than the last one !!!foobar - even higher in scope

We could do the inverse as well; if you append ! you can push variable down in scope.

Jesse

[1] I am not serious.



More information about the Python-Dev mailing list