Hello,
I’m using: SWI-Prolog version 7.6.4
I want the code to be able to pass parameter to Python code and read Python return value.
But what I’m getting is: the output
?- [python_lib].
true.
?- python_call(‘hello_world.py’, ‘delete’, Result).
Result = " ".
My code looks like this:
% your code here
python_call(File, Function, Result) :-
atomic_list_concat(['from ', File, ' import *;print(', Function, '())'], Command),
process_create(path(python), [['-c'],[Command]], [stdout(pipe(In))]),
read_string(In, _, Result).
python
%code
import mysql.connector
def delete():
connection = mysql.connector.connect(user='root',password='formag',host='localhost',database='test')
mycursor = connection.cursor()
sql_delete = 'DELETE from tabletest where id = 103'
mycursor.execute(sql_delete)
connection.commit()
connection.close()
return 'data deleted'
Please help me.