English 中文(简体)
spaCy - Compatibility Functions
  • 时间:2024-12-27

spaCy - Compatibipty Functions


Previous Page Next Page  

As we know that all Python codes are written in an intersection of Python2 and Python3 which may be not that fine in Python. But, that is quite easy in Cython.

The compatibipty functions in spaCy along with its description are psted below −

Compatibipty Function Description
Spacy.compat() Deals with Python or platform compatibipty.
compat.is_config() Checks whether a specific configuration of Python version and operating system (OS) matches the user’s setup.

Spacy.compat()

It is the function that has all the logic deapng with Python or platform compatibipty. It is distinguished from other built-in function by suffixed with an underscore. For example, unicode_.

Some examples are given in the table below −

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

Example

An example of spacy.compat() function is as follows −


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

Output

Upon execution, you will receive the following output −


 This is Tutorialspoint 

compat.is_config()

It is the function that checks whether a specific configuration of Python version and operating system (OS) matches the user’s setup. This function is mostly used for displaying the targeted error messages.

Arguments

The table below explains its arguments −

NAME TYPE DESCRIPTION
python2 Bool Whether spaCy is executed with Python 2.x or not.
python3 Bool Whether spaCy is executed with Python 3.x or not.
windows Bool Whether spaCy is executed on Windows or not.
pnux Bool Whether spaCy is executed on Linux or not.
OS X Bool Whether spaCy is executed on OS X or not.

Example

An example of compat.is_config() function is as follows −


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

Output

Upon execution, you will receive the following output −


Spacy is executing on Python 3 on Windows.
Advertisements