A memorandum of calling Python from Common Lisp

I found a library that can embed Python in Common Lisp called burgled-batteries, so I tried it. It is the memorandum.

environment

python


$ ros --version
roswell 17.5.8.78
$ ros run -- --version
SBCL 1.3.18
$ python --version
Python 2.7.13

Installation of burgled-batteries is easy from roswell.

$ ros install burgled-batteries

Call Python from Common Lisp

Let's call the function from the following module.

hello.py


#!/usr/bin/env python
# -*- coding: utf-8 -*-

def hello(name):
    print "Hi, {}! This is Python.".format(name)

Below is the SBCL REPL.

Execute Python function from CL


* (ql:quickload :burgled-batteries)
To load "burgled-batteries":
  Load 1 ASDF system:
    burgled-batteries
; Loading "burgled-batteries"
...
(:BURGLED-BATTERIES)
* (in-package :burgled-batteries)

* (startup-python) ;;Launch the Python interpreter
* (import "sys") ;;Import sys module

0
* (run "sys.path.append('./')") ;;Added because it does not search the current directory for some reason when importing
                                ;;run runs the embedded string in the current interpreter

* (import "hello") ;;Import hello module

* (run "hello.hello('Kojiro')") ;; hello.Call hello
Hi, Kojiro! This is Python.

Not only can it be embedded, but it can also be defined and called as a function.

Define and call a Python function in CL


* (defpyfun "hello.hello" (name)) ;; hello.hello of py hello.Defined as hello

HELLO.HELLO
* (hello.hello "Kojiro") ;;Can be called normally
Hi, Kojiro! This is Python.

Recommended Posts

A memorandum of calling Python from Common Lisp
[Python] A memorandum of beautiful soup4
A memorandum of python string deletion process
A memorandum of extraction by python bs4 request
Make a copy of a Google Drive file from Python
Python points from the perspective of a C programmer
A memorandum of kernel compilation
A small memorandum of openpyxl
A memorandum about correlation [Python]
A memorandum about Python mock
A memorandum of using eigen3
A memorandum of stumbling on my personal HEROKU & Python (Flask)
Different from the import type of python. from A import B meaning
I want to start a lot of processes from python
Python: Create a dictionary from a list of keys and values
Python> Read from a multi-line string instead of a file> io.StringIO ()
A record of patching a python package
Call a Python function from p5.js.
A good description of Python decorators
Touch a Python object from Elixir
A brief summary of Python collections
Existence from the viewpoint of Python
python / Make a dict from a list.
A memorandum of files under conf.d
Tips for calling Python from C
Memorandum of beginners Python "isdigit" movement
A memorandum of closure survey contents
A memorandum of understanding for the Python package management tool ez_setup
From a book that programmers can learn ... (Python): Review of arrays
[Python] Get the update date of a news article from HTML
A memorandum of scraping & machine learning [development technique] by Python (Chapter 4)
A memorandum of scraping & machine learning [development technique] by Python (Chapter 5)
A memorandum regarding the acquisition of the Python3 engineer certification basic exam
Python memorandum
Display a list of alphabets in Python 3
Python Memorandum 2
Learning notes from the beginning of Python 1
Mathematics is a graph of common tests.
A memorandum of speed of arbitrary degree diagonalization
Send a message from Python to Slack
Make a relation diagram of Python module
Memorandum of python beginners About inclusion notation
Note for Pyjulia calling Julia from Python
# 5 [python3] Extract characters from a character string
Connect a lot of Python or and and
A memorandum of understanding about django's QueryDict
Python memorandum
[python] Get a list of instance variables
[python] [meta] Is the type of python a type?
python memorandum
python memorandum
python + faker Randomly generate a point with a radius of 100m from a certain point
Create a deb file from a python package
Try calling Python from Ruby with thrift
Generate a class from a string in Python
Use Django from a local Python script
Manipulate BigQuery tables from a Python client
The story of blackjack A processing (python)
Python memorandum
python memorandum
Call a command from Python (Windows version)