It's a sample code I executed in micropython.
class Student:
def __init__(self,name):
self.name=name
self._name1=name
self.__name2=name
p=Student('abc')
print(p.name)
print(p._name1)
print(p.__name2)
and the output I received
abc
abc
abc
p.__name generally generates an error in the python interpreter.
Double underscore before a name isn't working in micropython
Re: Double underscore before a name isn't working in micropython
The class Student has no member __name, and the code you show runs fine without any error. Can you clarify what exactly the problem is?
*edit* ah, I assume you mean MicroPython does not support 'Private variables' i.e. https://docs.python.org/3/tutorial/clas ... -variables ?
*edit* ah, I assume you mean MicroPython does not support 'Private variables' i.e. https://docs.python.org/3/tutorial/clas ... -variables ?
Re: Double underscore before a name isn't working in micropython
stijn wrote: ↑Fri Jul 10, 2020 9:56 am*edit* ah, I assume you mean MicroPython does not support 'Private variables' i.e. https://docs.python.org/3/tutorial/clas ... -variables ?
Yes, I meant that. I forgot to write "private variables" in my query .
So,upy doesn't support private variables?
Re: Double underscore before a name isn't working in micropython
No, at least not in the way CPython does. See tests/micropython/const.py for what it does have: private const variables.
You could open an issue on github to request it, but it's going to be low priority I guess: it's a more or less obscure feature which doesn't get much use.
You could open an issue on github to request it, but it's going to be low priority I guess: it's a more or less obscure feature which doesn't get much use.