Am 22.07.2010 15:04, schrieb 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("<element param='boo'/>") 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("<element for='each'/>") print elem.for_ #????? elem = parse_xml("<element for_='each'/>") 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)
You raise a good point. However, I'd rather explicitly signify names instead of keywords: for $boo in $foo: if $boo is $None: print($hoo) else: return sorted($woo) That also has the advantage of introducing a measure of much needed compatibility with industry-leading web programming languages. Georg -- Thus spake the Lord: Thou shalt indent with four spaces. No more, no less. Four shall be the number of spaces thou shalt indent, and the number of thy indenting shall be four. Eight shalt thou not indent, nor either indent thou two, excepting that thou then proceed to four. Tabs are right out.