Python encapsulation

Asked

Viewed 59 times

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.

  • 2

    If you prefix the function name with a _, guy def _funcao, in making from modulo import * he will not be imported, but import _funcao keeps working. This serves?

1 answer

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

You are not signed in. Login or sign up in order to post.