class StackExchange(object): def __init__(self): pass class StackOverflow(StackExchange): # Coloque sua variável dentro de __init__, o que "evita" que ela vire pública. # Ela ainda é acessível através de _StackOverflow__language. def __init__(self, language = None): self.__language = 'en' if language is not None: self.__language = language @property # Objeto.language cai aqui def language(self): return self.__language @language.setter # Objeto.language = 'pt' cai aqui def name(self, language): self.__language = language if __name__ == "__main__": meu_so = StackOverflow('sv') # print(meu_so.__language) # Não funciona, descomente para testar print(meu_so.language) # Funciona
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question