Jump to content
softtouch

How to call a python function with parameter and get the result

Recommended Posts

I am playing for the first time a little with Python4Delphi.

 

When I have a python function, for example:

 

def Parser(src:str) -> str:
	s = "Test " + src
	return s

 

How do I call this from Delphi?

 

I have this script in a stringlist, and can call

 

PythonEngine1.ExecStrings(sl);

But how do I set the parameter "src" before calling the script, and how do I get the "s" value back after the call?

Edited by softtouch

Share this post


Link to post
uses
  VarPyth;
  
  ...
  var
    Res, S: string;
  
  PythonEngine1.ExecStrings(sl);
  Res := MainModule.Parser(S);
  

It would help to watch the tutorial videos and play with the Demos.

  • Like 1

Share this post


Link to post
1 hour ago, pyscripter said:

uses
  VarPyth;
  
  ...
  var
    Res, S: string;
  
  PythonEngine1.ExecStrings(sl);
  Res := MainModule.Parser(S);
  

It would help to watch the tutorial videos and play with the Demos.

Ok, that seems to work as expected. Thanks.

Edited by softtouch

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×