0

I want to know is there any to way to share my python code as library which people can use it but can't change it.

In ios, I can generate a static library and all .h file to other people. A programmer can get all methods he can use by viewing the .h file, but I don't know how to implement it in Python? how to tell a person which methods he can use like .h file?

remykits
  • 1,615
  • 3
  • 17
  • 20

1 Answers1

3

A Python convention (enshrined in PEP 8) is to name attributes with leading underscores:

def _foo():
    """You can call this function from your own code, but you
    really shouldn't because I might change or remove it at
    any time without warning"""
    modify_guts_of_module()

def __bar():
    """Hands off. This is for the module implementation, not for
    public consumption. You can't even see this unless you go out
    of your way, and why would you do that?"""
    release_the_hounds()

This is the Pythonic way of hiding attributes and telling others that they shouldn't use them.

Kirk Strauser
  • 27,753
  • 5
  • 45
  • 62