[Python-Dev] Set the namespace free!

2010-07-22 Thread Bartosz Tarnowski


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 = parse_xml("")
> 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 = parse_xml("")
> print elem.for_ #?
> elem = parse_xml("")
> 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

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Set the namespace free!

2010-07-25 Thread Bartosz Tarnowski


So OK, thank you for response.

No, I wasn't joking. I'm sorry, I didn't know that you Python guys get offended 
from being compared to PHP or Perl. Perhaps that shouldn't surprise me, though.


I have posted all of this here, because I was hoping this feature would be 
implemented secretly, without anyone knowing. Life isn't that simple it seems, 
I would have to go through all this PEP publication and stuff. Blame yourselves.


Reconsidering various ideas you have posted, I think the following solution 
would be best:
All alphanumeric sequences preceded by a dot (".") should not be treated as 
reserved words.


This would allow now reserved names as attributes without any change. Highest 
level identifiers would need to be simply preceded by a dot.


> boo.if = 3
> boo.with = hoo.as
> .while = 1
> .for = .def
> fun(.class="a")

This doesn't require any major change, does not break anything and as a side 
effect makes some very old code _valid_, at least syntactically.


I am going to repost this now on a valid list. Wish me luck, you opportunists.

--

Regards, haael

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com