Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

function "VarPyToStrings" #497

Copy link
Copy link
Closed
Closed
Copy link
@LucaBertoncini

Description

@LucaBertoncini
Issue body actions

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.