class.print method illegal

Diez B. Roggisch deetsNOSPAM at
Fri Jun 11 20:30:39 CEST 2004

> creates a syntax error.  Why can't a class have
> a method called "print"?  Doesn't seem to be
> any way it could be confused with the reserved
> print statement, or am I missing something?

Obviously, otherwise python wouldn't complain :)

As methods aren't much different from plain functions, I think we can agree
that a exception rule like "in methods, keywords can be used as names, but
not on normal functions" would be quite confusing.

Now consider this example:

>>> def foo():
>>>    pass
>>> foo
<function foo at 0x4052287c>

Now what would you expect a 

>>> def print():
>>>    pass

to do when print is issued alone on the commandline?

print as class method could be referenced as as klass.print of course, but
as I stated above, that would be inconsistent.

Another reason might be that creating a context-relevant re-interpretation
of keywords complicates the parser uneccesarily - with very limited


Diez B. Roggisch

More information about the Python-list mailing list