Git Product home page Git Product logo

Comments (4)

pyscripter avatar pyscripter commented on June 4, 2024

You can use the following to create lists or tuples

function VarPythonCreate( const AValues : array of const; ASequenceType : TSequenceType = stList ) : Variant; overload;

You could also use

function VarPythonEval( const APythonExpression : AnsiString) : Variant;

e.g VarPythonEval('[("name","=","Kelvin"),("title","=","MR")]')

from python4delphi.

kalmenchia avatar kalmenchia commented on June 4, 2024

Thanks for your help but this is what i tried, but could not get it work,

  1. drop a component TPythonDelphiVar and named it to list1 ,
  2. in my delphi code , put as suggested ,
    list1.value := VarPythonEval('[("name","=","Kelvin"),("title","=","MR")]');
  3. in my python script , i did the following,
    print 'list1' , 'list1.value' , type(list1.value)
  4. it printed output as
    list1 None <type 'NoneType'>

so it is not working for VarPythonEval

then when i tried and see if the TPythonDelphiVar whether it is
working with a simple string ,

  1. i change delphi code to
    list1.value :='test';
  2. when i check the printed output after execution of my python script is
    L1 test <type 'unicode'>
  3. so the python script and delphi code is working .

when i tried again using VarPythonCreate

  1. i change delphi code to
    declared local variable ,
    v : array of tvarrec;
    then

    ` SetLength(v,2);
    Format('test1',v);
    Format('test2',v);

    list1.value :=VarPythonCreate( v ,stList);`

  2. when i check the printed output after execution of my python script is
    L1 None

  3. so the python script and delphi code is NOT working .

is there anything i may have missed ? or the P4D has some bugs for creating list / tuple ?

from python4delphi.

pyscripter avatar pyscripter commented on June 4, 2024

Your original question did not mention TPythonDelphiVar and the like.

TPythonDelphiVar allows you to export simple Delphi values to Python.
VarPyth on the other hand is about manipulating Python objects in Delphi. (high-level)
WrapDelphi is about wrapping Delphi objects and exposing to Python.
Look at the numerous demos and study the code.

Assigning a custom variant to a TPythonDelphiVar.Value is not supported:
list1.value := VarPythonEval('[("name","=","Kelvin"),("title","=","MR")]');
Only simple variant types will work.

On the other hand you may try:
list1.ValueObject := ExtractPythonObjectFrom(VarPythonEval('[("name","=","Kelvin"),("title","=","MR")]'));
might work.

Instead of using a TPythonDelphiVar you can just add a TPythonModule and use the SetVar method.

Finally please do not use the issue tracker to ask for support. Use Stackoverflow, Delphi forums etc.

from python4delphi.

pyscripter avatar pyscripter commented on June 4, 2024

VarPythonEval('[("name","=","Kelvin"),("title","=","MR")]')
or just
GetPythonEngine.EvalString('[("name","=","Kelvin"),("title","=","MR")]')

creates a list of tuples. This is python, nothing to do with P4D.

You can use
function VarPythonCreate( const AValues : array of const; ASequenceType : TSequenceType = stList ) : Variant; overload;
to create either a list or a tuple depending on the second parameter.

from python4delphi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.