Another try at Python's selfishness
n.estner at gmx.de
n.estner at gmx.de
Fri Feb 3 07:14:33 EST 2006
> You could try running it to see:
>
> >>> class A:
>
> ... def test(a, **kwargs): return 1
> ...
> >>> class B:
>
> ... def test(b, **kwargs): return 2
> ...
> >>> test(a=A(), b=B())
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> NameError: name 'test' is not defined
>
> Oops! You have defined a name "test" in two namespaces, the class A and
> the class B, but there is no name "test" in the global namespace you are
> trying to run it in.
>
> Since namespaces are critical to Python, your test code is a problem that
> just cannot happen in Python. It is a non-issue. Python will not get
> confused between the two definitions of test.
I've been answering to Donn Cave's suggestion. Read it, and you will
understand what I mean.
> As near as I can tell, your original complaint might be solved simply: it
> seems to me that you are concerned about that extraneous "self" parameter
> for methods that don't need it:
No, I wasn't talking about functions that don't use the "self"
parameter. I rarely ever have such functions. I just tried to make the
example as short as possible.
More information about the Python-list
mailing list