2013-02-26 29 views
0

我想知道有沒有辦法共享我的Python代碼作爲庫,人們可以使用它,但無法更改它。如何將我的python代碼分享給其他人?

在ios中,我可以生成一個靜態庫和所有.h文件給其他人。程序員可以通過查看.h文件來獲取他可以使用的所有方法,但我不知道如何在Python中實現它?如何告訴一個人他可以使用哪種方法,比如.h文件?

+0

Is this [this](http://stackoverflow.com/questions/261638/how-do-i-protect-python-code)你感興趣的問題? – 2013-02-26 15:33:02

+0

一個更多的參考問題:嗯,我不需要保護我的代碼,也許只是一個參考問題:http://stackoverflow.com/questions/138521/is-it-feasible-to-compile-python-to-machine-code – 2013-02-26 15:34:34

+0

告訴人們他可以使用哪些方法 – remykits 2013-02-26 15:35:55

回答

3

一個Python約定(在PEP 8供奉)是名稱屬性與領先的下劃線:

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() 

這是隱藏屬性,並告訴別人他們不應該使用他們的Python的方式。

相關問題