maxkleiner / maXbox4

code compiler script studio
GNU General Public License v3.0
23 stars 10 forks source link

P4D Python4Delphi #27

Closed maxkleiner closed 7 months ago

maxkleiner commented 3 years ago

Add 20 Units + 8 Tutorials

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 1422 unit uPSI_PythonAction.pas

SIRegister_TFastStringStream(CL); procedure LoadJPEGResource(image1: TImage; aJpgImage: string); function CreateDOSProcessRedirected3(const CommandLine, InputFile, OutputFile, ErrMsg: string): Boolean; function SysCharSetToStr(const C: TSysCharSet): AnsiString; function StrToSysCharSet(const S: AnsiString): TSysCharSet; Procedure MaskFPUExceptions( ExceptionsMasked : boolean; MatchPythonPrecision: Boolean); Function GetOleVariantEnum( Collection : OLEVariant) : IGetOleVariantEnum); Function GetOleVariantArrEnum( Collection : OLEVariant) : IGetOleVariantEnum); Function GetRegisteredPythonVersions : TPythonVersions');

Total of Function Calls: 33848 SHA1: of 4.7.5.80 3E38A48072D4F828A4BE4A52320F092FE50AE9C3 CRC32: B6F69E19 29.8 MB (31,344,456 bytes)

maxkleiner commented 3 years ago

E2016 Array type required (Delphi) Go Up to Error and Warning Messages (Delphi)

This error message is given if you either index into an operand that is not an array, or if you pass an argument that is not an array to an open array parameter.

breitsch2 commented 1 year ago

`` with TPythonEngine.Create(Nil) do begin pythonhome:= PYHOME; try loadDLL; Execstr('datas = ["john", "john", "john", "jane", "jane", "jane"]'); execstr('datai = [1, 2, 3, 4, 5, 6, 7, 8, 9]'); println('unique data '+evalstr('list(set(datas))'));
println('even filter '+evalstr('list(filter(lambda x: x % 2 == 0, datai))')); //println('arbitrary values '+evalstr('list[map(int, datas().split())]'));
Println('Decimal: '+ EvalStr('import("decimal").Decimal(0.1)')); execstr('from math import ceil, log10, factorial'); execstr('import timeit'); //# Using a list for membership testing execstr('list_example = [1, 2, 3, 4, 5]'); println(evalstr('5 in list_example'));//+LF+ //' print("Found in list!")')); execstr('set_example = {1, 2, 3, 4, 5}'); println(evalstr('5 in set_example'));

   execstr('from collections import defaultdict; from itertools import islice');
   execstr('my_gen = (x**2 for x in range(10))');
   println('islice: '+evalstr('[islice(my_gen, 1, 9, 2)]'));

   execstr('input_list = [1, 2, 3, 4, 5]');

   //# Slow loop
   execstr('result_slow = []');
   execstr('for item in input_list:'+LF+
           '  squared = item**2'+LF+
           '  result_slow.append(squared)');
   println('slow: '+evalstr('result_slow')); 

   //# Optimized loop using a list comprehension
   println('fast:  '+evalstr('[item**2 for item in input_list]'));

   execstr('fast_time= timeit.timeit("[item**2 for item in [1,2,3,4,5]]")'); 
   println('timeittooks: '+evalstr('(f"fast_function took {fast_time:.2f}s")'));

   execstr('from memory_profiler import profile');   
   execstr(PIFUNC);   
   println('largelist: '+evalstr('large_list'));
   execstr('del large_list[:]');
   println('memleakfunction1: '+evalstr('memory_leak_function()')); 
   execstr('del large_list[:]');
   println('memleakfunction2: '+evalstr('memory_leak_function()')); 
   //execstr('large_list =[]');

   //execstr('import librosa');   
   //println('librosa versions: '+evalstr('librosa.show_versions()'));  
   //Println('Librosa: '+ 
     //    EvalStr('__import__("librosa").show_versions()'));  
 except
   raiseError;     
   //Try wordlists[len(words)]. () is a function call. When you do wordlists(..), python thinks that you are calling a function called wordlists which turns out to be a list. Hence the error.   
 finally 
   unloadDLL;      
   free;
 end; 

end; //with

maxkleiner commented 7 months ago

Works now An example in Python 3.11 64-bit:

https://stackoverflow.com/questions/2643850/what-is-a-good-way-to-do-countif-in-python

step = lambda x: sum(int(d) ** 2 for d in str(x)) iterate = lambda x: x if x in [1, 89] else iterate(step(x)) [iterate(x) for x in xrange(1, 20)] [1, 89, 89, 89, 89, 89, 1, 89, 89, 1, 89, 89, 1, 89, 89, 89, 89, 89, 1]