function call problem in class?
Davy
zhushenli at gmail.com
Wed Nov 14 03:48:16 EST 2007
On Nov 14, 4:10 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> En Wed, 14 Nov 2007 04:51:57 -0300, Davy <zhushe... at gmail.com> escribió:
>
> > I have write a simple class, I want the function two() to call private
> > function __one(), but there is an error :
> > NameError: global name '_simple__one' is not defined, how to work
> > around it
>
> > class simple:
> > def __one(self):
> > print "Hello"
> > def two(self):
> > __one()
> > print "world"
>
> > if __name__ == '__main__':
> > s = simple()
> > s.two()
>
> Note that your problem is not related to mangled names: replacing __one by
> one raises a similar exception.
> Remember that "self" is not implicit: you must use self.__one()
Hi Gabriel,
Thank you. now my code work well )
Davy
>
> "private" methods (and atributes in general) use a single underscore:
> _one. Double underscores __one are reserved for the (rare) cases when you
> want to ensure unique names (or name clashes are expected).
>
> --
> Gabriel Genellina
More information about the Python-list
mailing list