0
I wonder if I can encapsulate a function that is not in a class, like, just a function in the same code, so that it is only accessed inside the file, and when I import this file I can’t access this function directly.
0
I wonder if I can encapsulate a function that is not in a class, like, just a function in the same code, so that it is only accessed inside the file, and when I import this file I can’t access this function directly.
1
We don’t have a similar encapsulation to other languages. There is a way to show that something is encapsulated, however, according to the philosophy "Pythônica" we are all adults (different from what my java teacher thinks, saying that all users are tapirs and should be protected). In python, the way to show that a certain method or attribute is private, and should not be used is to put _
in front of their names.
Browser other questions tagged python
You are not signed in. Login or sign up in order to post.
If you prefix the function name with a
_
, guydef _funcao
, in makingfrom modulo import *
he will not be imported, butimport _funcao
keeps working. This serves?– Woss