SwiftHelloPython

Example for using PythonKit for Swift.

Arguments: <path to directory with Python scripts> <base name of Python script>.

It then uses the function replaceAllAs in the Python script to replace all “a” in the text “Aha” by “x”:

def replaceAllAs(text):
  return text.replace("a", "x")

To use PythonKit on Linux, you have to set the environment variable PYTHON_LIBRARY, e.g.:

export PYTHON_LIBRARY=/usr/lib/python3.6/config-3.6m-x86_64-linux-gnu/libpython3.6.so

Use find /usr/lib -name *libpython*.so to search for an appropriate Python library.

GitHub

View Github