Closed maxkleiner closed 2 years ago
Thanks to Python4Delphi we now can eval or exec some Python code in our scripts. This version 4.7.5.80 July 2021 allows us with the help of a Python Dll and an environment with modules in site-packages execute Py-functions. But the most is only available in a 32-bit space, possible also with 64-bit Python means the call of the external shell (ExecuteShell) with installed Python versions to choose from. By the way also a Python4Lazarus is available.
1413 unit uPSI_PythonEngine.pas _P4D_Beta 1414 unit uPSI_VclPythonGUIInputOutput; 1415 unit uPSI_VarPyth; 1416 unit JclUsesUtils; 1417 unit uPSI_cParameters; 1418 unit uPSI_WDCCMisc; (uPSI_cFileTemplates); 1419 uPSI_WDCCOleVariantEnum.pas 1420 unit uPSI_WDCCWinInet.pas _WDCC 1421 uPSI_PythonVersions.pas P4D 1422 unit uPSI_PythonAction.pas P4D
Script with Python in maXbox: Procedure PYLaz_P4D_Demo; //https://wiki.freepascal.org/Python4Delphi var eng : TPythonEngine; Out1: TPythonGUIInputOutput; begin eng:= TPythonEngine.Create(Nil); Out1:= TPythonGUIInputOutput.create(nil) Out1.output:= pyMemo; //debugout.output; //memo2; Out1.RawOutput:= False; Out1.UnicodeIO:= False; out1.displaystring('this string') //eng.IO:= Out1; //eng.free; eng.LoadDll; eng.IO:= Out1; if eng.IsHandleValid then begin writeln('DLLhandle: '+botostr(eng.IsHandleValid)) WriteLn('evens: '+ eng.EvalStringAsStr('[x2 for x in range(15)]')); WriteLn('gauss: '+ eng.EvalStringAsStr('sum([x for x in range(101)])')); WriteLn('gauss2: '+ eng.EvalStr('sum([x % 2 for x in range(10100)])')); writeln('syncheck '+ botostr(eng.CheckEvalSyntax('print("powers:",[x2 for x in range(10)])'))); eng.ExecString('print("powers:",[x2 for x in range(10)])'); eng.ExecString(PYCMD); writeln('ExecSynCheck1 '+botostr(eng.CheckExecSyntax(myloadscript))); writeln('ExecSynCheck2 '+ botostr(eng.CheckExecSyntax(filetostring(PYSCRIPT)))); eng.ExecString(filetostring(PYSCRIPT)); writeln(eng.Run_CommandAsString('print("powers:",[x2 for x in range(10)])',eval_input)); writeln(eng.Run_CommandAsString('sum([x for x in range(201)])',eval_input)); end else writeln('invalid library handle! '+Getlasterrortext); writeln('PythonOK '+botostr(PythonOK)); out1.free; eng.free; end;
Closed with V 4.7.5.90
Tech Notes maXbox 4.7.5.90 V October 2021 mX47
add uPSI_flcFloats.pas to complete Fundamentals5 Registermethod: count, capacity in TNNetList with CL.Add(TNNetList) do RegisterMethod(@TNNetList.Count, 'Count'); alias flots() - floattostr() CL.AddDelphiFunction('Function flots( const A : Float) : String'); plus resources MOON_FULL, maxbox4logo.jpg Bugfix TSize Type CL.AddClassN(CL.FindClass('TOBJECT'),'TInteger'); Bigints for BigFloat
Docu of main Neural Unit for maXbox: http://www.softwareschule.ch/examples/uPSI_NeuralNetworkCAI.txt http://www.softwareschule.ch/examples/uPSI_neuralnetworkcai.txt http://www.softwareschule.ch/examples/uPSI_neuralvolume.txt http://www.softwareschule.ch/examples/uPSI_neuraldatasets.txt http://www.softwareschule.ch/examples/uPSI_neuralfit.txt Source https://github.com/joaopauloschuler/neural-api
--- v3 +++ v4 @@ -21,6 +21,8 @@ 1418 unit uPSIWDCCMisc; (uPSIcFileTemplates); 1419 uPSIWDCCOleVariantEnum.pas 1420 unit uPSIWDCCWinInet.pas WDCC +1421 uPSI_PythonVersions.pas +1422 unit uPSI_PythonAction.pas
SIRegister_TFastStringStream(CL); procedure LoadJPEGResource(image1: TImage; aJpgImage: string); @@ -31,9 +33,9 @@ Procedure MaskFPUExceptions( ExceptionsMasked : boolean; MatchPythonPrecision: Boolean); Function GetOleVariantEnum( Collection : OLEVariant) : IGetOleVariantEnum); Function GetOleVariantArrEnum( Collection : OLEVariant) : IGetOleVariantEnum); +Function GetRegisteredPythonVersions : TPythonVersions');
-Total of Function Calls: 33840 -SHA1: of 4.7.5.80 C913C075CD890B03049047AB65499A562681BDF5 -CRC32: B6F69E19 29.8 MB (31,328,584 bytes) +Total of Function Calls: 33848 +SHA1: of 4.7.5.80 3E38A48072D4F828A4BE4A52320F092FE50AE9C3 +CRC32: B6F69E19 29.8 MB (31,344,456 bytes)