以遞迴方式導入 Python 程式碼.

此功能已經內建在 Leo Editor 的 scripts/scripts.leo 中, 程式碼如下:

1
2
3
4
5
6
7
8
9
'''Recursively import all python files in a directory and clean the result.'''

c.recursiveImport(
    dir_ = r'./',
    kind = '@clean', # The new best practice.
    one_file = False,
    safe_at_file = False,
    theTypes = None, # Same as ['.py']
)


將此一節點從 scripts.leo 取出後, 存入要 import 程式碼的專案目錄中, 然後存為 .leo 後, 按下 Ctrl+b 就可以運行, 當然導入之後, 所有節點都以 @path 開頭, 表示此 leo 檔案並未與外部檔案直接存取互動, 而是將程式碼從外部檔案中, 架構性地取出, 並且存在 leo 專案檔中.

另外, 也可以透過下列程式導入特定目錄中的 Python 程式:

1
2
import leo.core.leoImport as leoImport
leoImport.importFiles(aDirectory, ".py")

Comments

comments powered by Disqus