[Tutor] Very wierd namespace problem

Kent Johnson kent37 at tds.net
Fri Jul 17 19:02:00 CEST 2009


On Fri, Jul 17, 2009 at 12:04 PM, Amit Sethi<amit.pureenergy at gmail.com> wrote:

> now I have created a class with some functions defined in it but the
> thing is that they are named in a completely different manner?????(or
> so I think)
>
> <__main__.SmPriceWindow instance at 0x9dd448c>
> ['_SmPriceWindow__add_columns', '_SmPriceWindow__create_model',
> '_SmPriceWindow__review_button_click', '_SmPriceWindow__show_all',
> '_SmPriceWindow__url_button_click', '__doc__', '__init__',
> '__module__', 'model', 'tree', 'window']
> Traceback (most recent call last):
>  File "smnotebook3.py", line 135, in price_button_pressed
>    sw.__show_all()
> AttributeError: SmPriceWindow instance has no attribute '__show_all'
>
> I have refered to these functions(__add_columns ,__create_model etc
> ... as self.__add_columns as would be expected in the class itself  )

Names beginning with __ are 'mangled' to make them sort of secret.
This is a feature:
http://docs.python.org/reference/expressions.html#index-889

Kent


More information about the Tutor mailing list