天天看點

python中的子產品和包是什麼如何自定義并使用_如何從不是包的自定義存儲庫中添加子產品?python...

我曾嘗試将sys.path.append()與os.getcwd()一起使用,但沒有成功。在

源代碼來自here,我已經下載下傳并提取了它們:[email protected]:~/test$ wget https://github.com/alvations/DLTK/archive/master.zip

[email protected]:~/test$ tar xvzf master.zip

[email protected]:~/test$ cd DLTK-master/; ls

dltk

[email protected]:~/test/DLTK-master$ cd dltk/; ls

tokenize

[email protected]:~/test/DLTK-master/dltk$ cd tokenize/; ls

abbrev.lex jwordsplitter-3.4.jar rbtokenize.pl

banana-split-standalone-0.4.0.jar koehn_senttokenize.pl splicer.py

igerman98_all.xml koehn_wordtokenize.pl tokenizer.py

__init__.py nonbreaking_prefix.de

[email protected]:~/test/DLTK-master/dltk/tokenize$ cat __init__.py

from tokenizer import punct_tokenize, rb_tokenize

from tokenizer import koehn_tokenize, deupunkt_tokenize

from splicer import jwordsplitter, jwordsplitteralvas

這些是我想從~/text/目錄通路的函數,例如koehn_tokenize函數。但我似乎無法将子產品/函數添加到python解釋器中。在

^{pr2}$

從位于~/test/目錄的python解釋器中,如何通路dltk.tokenize子產品?

如果将cd轉換為~/test/DLTK-master/dltk/tokenize,則函數有效:[email protected]:~/test$ cd DLTK-master/dltk/tokenize/

[email protected]:~/test/DLTK-master/dltk/tokenize$ python

Python 2.7.5+ (default, Sep 19 2013, 13:48:49)

[GCC 4.8.1] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> from __init__ import koehn_tokenize

>>>

但是我不想在使用python解釋器之前将cd放入~/test/DLTK-master/dltk/tokenize。我需要在python中添加子產品/函數。在