class X: ... def print(self, x): ... print "printing", x ... x = X() x.print(1)
Mark, (and the rest of python-dev) There was a thread here a few weeks ago (or so, I seem to have misplaced that particular thread :P) about using Python keywords as identifiers in some cases. You needed that ability for .NET-Python, where the specs say any identifier should be possible as methods and attributes, and there were some comments on the list on how to do that (by Guido, for one.) Well, the attached patch sort-of does that. I tried making it a bit nicer, but that involved editing all places that currently use the NAME-type node, and most of those don't advertise that they're doing that :-S The attached patch is in no way nice, but it does work: printing 1
x.print
x.assert = 1
However, it also allows this at the top level, currently:
def print(x): ... print "printing", x ...
print(1) 1 globals()['print'](1)
import printer printer.print
printer.print(1, 2)
which results in some unexpected behaviour:
printing 1
But when combining it with modules, it does work as expected, of course:
# printer.py:
def print(x, y):
print "printing", x, "and", y
#
printing 1 and 2
Another plus-side of this particular method is that it's simple and
straightforward, if a bit maintenance-intensive :-) But the big question is:
is this enough for what you need ? Or do you need the ability to use
keywords in *all* identifiers, including variable names and such ? Because
that is quite a bit harder ;-P
--
Thomas Wouters
participants (4)
-
Guido van Rossum
-
M.-A. Lemburg
-
Neil Hodgson
-
Thomas Wouters