B4J Question Shell interacting with Python and Calling Functions


Licensed User
Hi All, i have the need to run a few python scripts in B4J, i came across the Jython library which works very good, but unfortunately i can not get the Bluetooth Module to work, I believe it is because that package is not installed in Jython and I believe that Jython also doesn't support modules that have C dependencies.

With that said, i've tried using the Shell library which works great, i'am able to run a scrip that searches for any bluetooth devices and displays the names and mac address.
The python code is the following:
import bluetooth

print("performing inquiry...")

nearby_devices = bluetooth.discover_devices(
        duration=8, lookup_names=True, flush_cache=True, lookup_class=False)

print("found %d devices" % len(nearby_devices))

for addr, name in nearby_devices:
        print("  %s - %s" % (addr, name))
    except UnicodeEncodeError:
        print("  %s - %s" % (addr, name.encode('utf-8', 'replace')))
My question is this, how can I call a function inside a python script using Shell? Can this be done? if so does anyone have any examples?

Thanks in advance.



Licensed User
There are probably other options, however you can create a batch file and run it with cmd.exe /c bat.bat
What i'm really trying to do is call functions from a python script and have a GUI interface, i found this library which allows me to do just that https://www.b4x.com/android/forum/threads/jpython.61094/ unfortunately it doesn't allow me to use certain modules which are not compatible with Jython.

The only easy option i can think of is using the JShell library, but i need to know how to call a function from a python script when the user presses on a control like a button etc..

Upvote 0