Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Using Python as an optional scripting language instead of VB script. #449

Closed Answered by pyscripter
Andyk1234 asked this question in Q&A
Discussion options

Hi,

I currently use VBscript as a scripting language which works quite well as I can expose my apps API to the scripts via type libraries and I am confused how to fit python into the same scripting paradigm.

Currently I can load load several scripts into my script objects, instantiate VBscript interpreters for each one, run main functions to initialise them and then the functions become available for my app to use. When I edit a script, I can reset the script interpreter, send it the new code and reinitialise it.

I can't seem to do this with python as it only allows 1 interpreter to run in the same process.

Is there a way to fit Python within this paradigm?

Should I use 1 interpreter with a hidden main script and make my effective scripts as modules?

The scripts don't need to run concurrently and they need to be in the same process.

Also my end users may not want to install python or use python scripts, so can I still use the design time components or will they cause errors if no python distro is installed?

You must be logged in to vote

I do not know what your VB scripts are doing, but most likely you need to convert them to python code (not necessarily a module) and use one of the ExecStrings methods to run them. Before doing any work, it is worth watching the tutorials and playing with some of the demos.

Replies: 2 comments 3 replies

Comment options

  • You do not need a separate interpreter for each script. You can use one python interpreter to run all scripts.
  • If you do not want to require users to install python, you can deploy a minimal python with your app.
  • Exposing you Delphi classes, records and interfaces to python is very easy with P4D.

For a popular application that uses python as a scripting language using P4D, have a look at https://github.com/Alexey-T/CudaText

You must be logged in to vote
0 replies
Comment options

Thanks,

when you say...

"You do need a separate interpreter for each script."

do you mean, did you miss out the "not" ?

You must be logged in to vote
3 replies
Comment options

do you mean, did you miss out the "not" ?

Indeed. Corrected above.

Comment options

Thanks,

Should I convert my equivalent VB scripts to Python modules?

Comment options

I do not know what your VB scripts are doing, but most likely you need to convert them to python code (not necessarily a module) and use one of the ExecStrings methods to run them. Before doing any work, it is worth watching the tutorials and playing with some of the demos.

Answer selected by Andyk1234
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /