TimWhiting / dartpy

An experiment in embedding Python in Dart via dart ffi and the Python c-api
68 stars 10 forks source link

How to pass arguments to the python script? #4

Closed shaoyijia closed 8 months ago

shaoyijia commented 2 years ago

Hi, I'm trying to use your API to integrate a piece of python script to my flutter app which is written by Dart. Is it possible to pass arguments to the python script? If so, what should I do?

I noticed that the second example in your README.md pass arguments to the imported function. However, I failed to fully understand it. If my understanding is correct, multiply is a method in multiply.py. But where should I put the multiply.py to make it successfully imported by your API?

Actually, in my need, I hope that users don't need to explicitly download additional python scripts as long as they have some python packages installed on their workstation. So I'm really curious whether I can pass arguments using the inline way.

Thanks for your help!

TimWhiting commented 8 months ago

Sorry this took me forever to reply. I'm assuming you eventually figured it out?

Yes, it is possible to pass arguments to the python functions. Using the Python C API we can call python code directly, (not via an external process or anything). Yes the person running the code would need to have the scripts on their PYTHONPATH, which is as normal for Python.

shaoyijia commented 8 months ago

Thank you for your reply!!(the notification email actually surprises me :) Yeah, I resorted to the low level Python C API to resolve this problem. I'll close this issue!