Is it advisable to replace 'self' with '_' or 'I' or something shorter?
Edward K. Ream
edream at tds.net
Sat Jan 11 14:26:21 EST 2003
Here is a copy of a posting I sent to another thread:
I often use the following idiom for methods in Leo:
def spam(self,...):
v = self
# Now use v instead of self
The idea is to use one-letter codes for common classes. Leo uses c for
"commanders", f for frames, t for Tk.Text widgets or "tnodes", v for
"vnodes", u for "undoer" objects, etc. With this idiom, objects of the
class in which the method exists are handled just like all other objects.
It saves typing and makes the type of all objects clear.
One could use:
def spam,(v,...):
# etc.
instead, but that would violate the coding guidelines (and pychecker would
complain by default).
This scheme is simple, clear, concise, effective. It has no drawbacks that
I know of.
Edward
--------------------------------------------------------------------
Edward K. Ream email: edream at tds.net
Leo: Literate Editor with Outlines
Leo: http://personalpages.tds.net/~edream/front.html
--------------------------------------------------------------------
More information about the Python-list
mailing list