You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Code := 'aList.append("Py first element!")' + sLineBreak +
'aList.append("Py second element!")' + sLineBreak +
'aList = sorted(aList)' + sLineBreak;
PyEngine.ExecString(Code);
if VarIsPythonList(MainModule.aList) then
begin
Items := TStringList.Create;
VarPyToStrings(MainModule.aList, Items);
writeln(Items.Text);
Items.Free;
end;
PyEngine.Free;
end.
I noticed a strange behavior of the "VarPyToStrings" function. I had to modify it in this way to get the desired output.
procedure VarPyToStrings(const AValue : Variant; const AStrings: TStrings);
var
V: Variant;
begin
for V in VarPyIterate(AValue) do
AStrings.Add(VarPythonAsString(V));
end;
The text was updated successfully, but these errors were encountered:
Hi, today I started experimenting with your amazing library. I am using FreePascal version 3.3.1 and this is my OS: Linux Mint21 5.15.0-136-generic.
This is a simple test I did.
program TestPython1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
Classes, PythonEngine, VarPyth;
var
PyEngine : TPythonEngine;
Code : String;
Items : TStringList;
begin
PyEngine := TPythonEngine.Create(nil);
PyEngine.LoadDll;
MainModule.aList := VarPythonCreate(['First element', 'Second element', 'Third element'], stList);
Code := 'aList.append("Py first element!")' + sLineBreak +
'aList.append("Py second element!")' + sLineBreak +
'aList = sorted(aList)' + sLineBreak;
PyEngine.ExecString(Code);
if VarIsPythonList(MainModule.aList) then
begin
Items := TStringList.Create;
VarPyToStrings(MainModule.aList, Items);
writeln(Items.Text);
Items.Free;
end;
PyEngine.Free;
end.
I noticed a strange behavior of the "VarPyToStrings" function. I had to modify it in this way to get the desired output.
procedure VarPyToStrings(const AValue : Variant; const AStrings: TStrings);
var
V: Variant;
begin
for V in VarPyIterate(AValue) do
AStrings.Add(VarPythonAsString(V));
end;
The text was updated successfully, but these errors were encountered: