Comments (4)
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.
Thanks for your help but this is what i tried, but could not get it work,
- drop a component TPythonDelphiVar and named it to list1 ,
- in my delphi code , put as suggested ,
list1.value := VarPythonEval('[("name","=","Kelvin"),("title","=","MR")]');
- in my python script , i did the following,
print 'list1' , 'list1.value' , type(list1.value) - 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 ,
- i change delphi code to
list1.value :='test';
- when i check the printed output after execution of my python script is
L1 test <type 'unicode'> - so the python script and delphi code is working .
when i tried again using VarPythonCreate
-
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);`
-
when i check the printed output after execution of my python script is
L1 None -
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.
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.
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)
- Add support for Py_NewInterpreterFromConfig
- Running Demos from Delphi-12 HOT 1
- Pagecontrol.ActivePage wrapper function causes AV error HOT 8
- "demo33 -- three interpreter" causes the thread to hang. HOT 7
- floating point division by zero HOT 1
- python dll HOT 1
- VarPyIterate raises EPyStopIteration exception with message 'Stop Iteration' HOT 2
- numpy and TTask HOT 8
- Running python code in Delphi threads issue HOT 1
- Pyhton4Delphi and streamlit HOT 3
- How to specify the path to Python libraries? HOT 4
- Run the .py file immediately with parameters HOT 8
- How can I output the results of a py script? HOT 9
- OnSendUniData event does not work HOT 4
- Wrongly throwing an exception from the wrapping object HOT 2
- A little problem HOT 2
- Error in ExtractPythonObjectFrom when creating Enum? HOT 1
- [dcc64 fatal error] PythonVcl.dpk: F2084 Internal Error on RAD Studio 12.1 HOT 6
- Minor: Typo in error message
- Pandas with Python 3.12 HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python4delphi.