-
Content Count
1025 -
Joined
-
Last visited
-
Days Won
66
pyscripter last won the day on July 3
pyscripter had the most liked content!
Community Reputation
793 ExcellentTechnical Information
-
Delphi-Version
Delphi 12 Athens
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
-
TypeError: 'PythonDelphiVar' object cannot be interpreted as an integer"
pyscripter replied to Jacek Laskowski's topic in Python4Delphi
Here the following runs fine (without importing builtins): procedure TForm1.Button1Click(Sender: TObject); var PyEngine: TPythonEngine; PyHeight: Integer; PyIO: TPythonGUIInputOutput; PyModule: TPythonModule; PyWidth: Integer; VarHeight: TPythonDelphiVar; VarWidth: TPythonDelphiVar; begin PyWidth := 80; PyHeight := 40; PyEngine := TPythonEngine.Create(nil); PyModule := TPythonModule.Create(nil); PyIO := TPythonGUIInputOutput.Create(nil); try PyIO.Output := Memo1; PyEngine.IO := PyIO; PyEngine.UseLastKnownVersion := True; PyEngine.AutoLoad := False; PyEngine.AutoUnload := False; PyModule.Engine := PyEngine; PyModule.ModuleName := '__main__'; try PyEngine.LoadDll; except on E: Exception do begin ShowMessage('Error at load Python: ' + E.Message); Exit; end; end; PyModule.Initialize; //PyEngine.PyRun_SimpleString('import builtins; __builtins__ = builtins'); VarWidth := TPythonDelphiVar.Create(nil); VarWidth.Engine := PyEngine; VarWidth.Module := '__main__'; VarWidth.VarName := 'WIDTH'; VarWidth.Initialize; VarWidth.Value := PyWidth; VarHeight := TPythonDelphiVar.Create(nil); VarHeight.Engine := PyEngine; VarHeight.Module := '__main__'; VarHeight.VarName := 'HEIGHT'; VarHeight.Initialize; VarHeight.Value := PyHeight; var Source := ''' import math result = sum(i * i for i in range(1, 11)) print("Suma kwadratów od 1 do 10 to:", result) canvas = [[' ' for _ in range(WIDTH.Value)] for _ in range(HEIGHT.Value)] print(canvas) '''; PyEngine.ExecString(Utf8Encode(Source), '__main__'); finally VarWidth.Free; VarHeight.Free; PyIO.Free; PyModule.Free; PyEngine.Free; end; end; However you should not call the module '__main__', since by doing that you will be overriding the default python module with the same name. Call the module something else say my_module and then add to your python script: from my_module import WIDTH, HEIGHT -
TypeError: 'PythonDelphiVar' object cannot be interpreted as an integer"
pyscripter replied to Jacek Laskowski's topic in Python4Delphi
The above should also be: HEIGHT.Value = 40 WIDTH.Value = 60 You should not need to import builtins. Not sure what the problem was. -
TypeError: 'PythonDelphiVar' object cannot be interpreted as an integer"
pyscripter replied to Jacek Laskowski's topic in Python4Delphi
canvas = [[' ' for _ in range(WIDTH)] for _ in range(HEIGHT)] needs to be canvas = [[' ' for _ in range(WIDTH.Value)] for _ in range(HEIGHT.Value)] -
TypeError: 'PythonDelphiVar' object cannot be interpreted as an integer"
pyscripter replied to Jacek Laskowski's topic in Python4Delphi
Does reversing the order help? VarWidth.Value := PyWidth; VarWidth.Initialize; -
Error 'No module named' on importing python-file
pyscripter replied to Brent's topic in Python4Delphi
I am confused. You are talking about your own python file (CustomClasses), but also something you installed via pip. For python to find your file it needs to be either on the python path or on the current directory. Run the following using P4D: import sys import os print(sys.path) print(os.getcwd()) print(sys.executable) and check the values of the path and the current directory. Also check which python version you are using. -
Multi-phase extension module initialization has been implemented. See Multi-phase module initialization implemented · pyscripter/python4delphi · Discussion #505 for details. What this means is that you can now create python extension modules with P4D that can be used with sub-interpreters including those created with the new concurrent.interpreters module of python 3.14.
-
Looking for CBuilder/VS help on C open source project
pyscripter replied to Vincent Parrett's topic in Job Opportunities / Coder for Hire
Another abandonware of Microsoft! It first sounded real good. -
Looking for CBuilder/VS help on C open source project
pyscripter replied to Vincent Parrett's topic in Job Opportunities / Coder for Hire
Wow. Once, I had very high hopes for this technology, but it became another abandonware of Microsoft. Have you considered using python (pyscripter/python4delphi: Free components that wrap up Python into Delphi and Lazarus (FPC))? I guess though you were using JScript and you want to stick to JavaScript. For JavaScript there is also Microsoft's ChacraCore, which used to be the JavaScript engine of the old Edge browser. There is a good Delphi wrapper. See also the blog. -
Looking for CBuilder/VS help on C open source project
pyscripter replied to Vincent Parrett's topic in Job Opportunities / Coder for Hire
@Vincent ParrettOut of curiosity, what are you using QuickJS for? -
Interesting read about Sleep(0/1) and SwitshToThread
pyscripter replied to Tommi Prami's topic in Windows API
By the way, TThread.Yield is the cross-platform way to call SwitchToThread. -
pascal-process: A new library for running processes and redirecting their output.
pyscripter replied to pyscripter's topic in I made this
I set the pascal-process buffer to 4 *1024 for the comparison.- 23 replies
-
- open-source
- process
-
(and 1 more)
Tagged with:
-
pascal-process: A new library for running processes and redirecting their output.
pyscripter replied to pyscripter's topic in I made this
Although, it does not look like it, the alertable wait does the same.- 23 replies
-
- open-source
- process
-
(and 1 more)
Tagged with:
-
pascal-process: A new library for running processes and redirecting their output.
pyscripter replied to pyscripter's topic in I made this
@Kas Ob. There are many ways to skin a cat. The approach adopted in pascal-process uses asynchronous (overlapped) IO with alertable wait. So there are no tight loops with Sleep, or additional threads for reading. I think it is as efficient as it can get. I compared your code to pascal-process by using: 'cmd /v:on /c "set start=!time! && dir C:\Windows /s && set end=!time! && echo Start time: !start! && echo End time: !end!"'#13#10 Your code: Start time: 14:31:08.09 End time: 14:31:22.64 about 14 secs pascal-process Start time: 14:35:54.74 End time: 14:36:04.58 about 9 secs. To make sure disk caching did not play a role, I run your code again, with similar results: Start time: 15:01:58.56 End time: 15:02:14.17 About 15 secs. Of course one should not read much in a single benchmark. But, I do not see any reason your code is faster or otherwise better than the one used in pascal-process. Regarding AttachConsole do you happen to know, in which Delphi version it was first declared?- 23 replies
-
- open-source
- process
-
(and 1 more)
Tagged with:
-
pascal-process: A new library for running processes and redirecting their output.
pyscripter replied to pyscripter's topic in I made this
@Kas Ob. This is an open-source project. You are welcome to create PRs, open issues, make suggestions etc.- 23 replies
-
- open-source
- process
-
(and 1 more)
Tagged with:
-
For some reason, I do not see the May Patch.