[Tutor] underscore function
Pujo Aji
ajikoe at gmail.com
Thu Apr 13 09:36:56 CEST 2006
Python programmers prefer to use name convention to make method of class
"looks" private.
Usually they use of '_' before the private method or private attribute name.
This private method like the one you mentioned def _abc is not intentionaly
used outside the class other then it is used among other class methods
privately.
Example:
class A:
def __init__(self, myvar):
self._myvar = myvar
def _makedouble(self):
'''this method is private'''
self._myvar = self._myvar * 2
def printvarADouble(self):
self._makedouble()
print self._myvar
def main():
o = A(2)
o.printvarADouble() # 4
You may use def abc instead of def _abc, again it is only a convention.
Hope this helps,
pujo
On 4/13/06, linda.s <samrobertsmith at gmail.com> wrote:
>
> I got a sample code and found some
> function definition looks like def _abc
> There is one underscore before the function name "abc",
> what does it mean?
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060413/132989e2/attachment.htm
More information about the Tutor
mailing list