spaCy - 相容性函式



我們知道,所有 Python 程式碼都編寫在 Python 2 和 Python 3 的交集中,這在 Python 中可能不太好。但是,在 Cython 中這很容易。

下面列出了 spaCy 中的相容性函式及其描述:

相容性函式 描述
Spacy.compat() 處理 Python 或平臺相容性。
compat.is_config() 檢查 Python 版本和作業系統 (OS) 的特定配置是否與使用者的設定匹配。

Spacy.compat()

它是處理 Python 或平臺相容性的所有邏輯的函式。它以下劃線結尾,區別於其他內建函式。例如,unicode_。

下面表格中給出了一些示例:

名稱 Python 2 Python 3
compat.bytes_ str bytes
compat.unicode_ unicode str
compat.basestring_ basestring str
compat.input_ raw_input input
compat.path2str str(path) with .decode('utf8') str(path)

示例

spacy.compat() 函式的示例如下:

import spacy
from spacy.compat import unicode_
compat_unicode = unicode_("This is Tutorialspoint")
compat_unicode

輸出

執行後,您將收到以下輸出:

'This is Tutorialspoint'

compat.is_config()

它是檢查 Python 版本和作業系統 (OS) 的特定配置是否與使用者的設定匹配的函式。此函式主要用於顯示目標錯誤訊息。

引數

下表解釋了它的引數:

名稱 型別 描述
python2 布林值 spaCy 是否使用 Python 2.x 執行。
python3 布林值 spaCy 是否使用 Python 3.x 執行。
windows 布林值 spaCy 是否在 Windows 上執行。
linux 布林值 spaCy 是否在 Linux 上執行。
OS X 布林值 spaCy 是否在 OS X 上執行。

示例

compat.is_config() 函式的示例如下:

import spacy
from spacy.compat import is_config
if is_config(python3=True, windows=True):
   print("Spacy is executing on Python 3 on Windows.")

輸出

執行後,您將收到以下輸出:

Spacy is executing on Python 3 on Windows.
廣告

© . All rights reserved.