B4A Library NinjaPython - Use Python Scripts in B4A

Work in progress - Work in progress - Work in progress - Work in progress - Work in progress
np.jpg

Work in progress - Work in progress - Work in progress - Work in progress - Work in progress

The NinjaPython B4A library brings you the ability of utilizing the Python language inside your B4A games and apps.
This can range from a few lines of code to entire scripts or object oriented modules, the choice is yours.

upload_2017-10-29_22-7-17.png

Quickstart:
- Switch 'Compilation Mode' to Release
- Download the library files and place them in your B4A external libraries folder.
- Option A: Download the resource files and place them in your project's Files folder.
- Option B: Download the test project below.
- See the 'usage' example below.​

Practice:

Features:
- CPython Interpreter 2.7.9
- Python Standard Library
- x86 and ARM compatible
- Ongoing development
Wishlist:
- Dedicated function calls
- Passing and returning B4A objects such as lists and maps
- Support for 3rd party libraries
Price (pay what you want):
Test project:

KanBan board:

Library files (1.03):

Resource files:

Usage:
B4X:
Dim Py As NinjaPython
Py.Initialize
Py.Exec($"
def SayHello(subject):
    print 'Hello, ' + subject + '!'
"$)

...
...
...
...

Py.Exec("SayHello('world')") 'Outputs and returns 'Hello, world!'
Py.Finalize

Learn:
/SPOILER]
Enjoy! :)
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Great but what does it do
 

wonder

Expert
Licensed User
Longtime User

Star-Dust

Expert
Licensed User
Longtime User
Sorry I did not explain well. I know what Phyton is, but I want to know what the code is .... is a phyton interpreter written in B4A?
 

Star-Dust

Expert
Licensed User
Longtime User
That's really interesting.
is 100% compatible or are you currently working for?
 

wonder

Expert
Licensed User
Longtime User
The official release is almost ready, so stay tuned! ;)

Features:
-
Python 2.7.9
- ARM and x86
- User imports
- Python Standard Library
- Code execution (returns stdstdout)

Work-in-progress:
- Library imports (eg. NumPy)
- Direct function calls

Price (your choice):
- Paypal me 1 pizza or 2 beers! :D
- Free
 
Last edited:

Husam

Member
Licensed User
Many thanks for your work , i just test your python test then i got this error

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
[NinjaPython] ARM CPU detected
Error occurred on line: 59 (Main)
java.io.FileNotFoundException: python2.7.zip
    at android.content.res.AssetManager.openAsset(Native Method)
    at android.content.res.AssetManager.open(AssetManager.java:331)
    at android.content.res.AssetManager.open(AssetManager.java:305)
    at com.ninjadynamics.ninjapython.NinjaPython.copyAssetFile(NinjaPython.java:122)
    at com.ninjadynamics.ninjapython.NinjaPython.install(NinjaPython.java:109)
    at com.ninjadynamics.ninjapython.NinjaPython.Initialize(NinjaPython.java:92)
    at com.ninjadynamics.python.main._activity_resume(main.java:460)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
    at com.ninjadynamics.python.main.afterFirstLayout(main.java:108)
    at com.ninjadynamics.python.main.access$000(main.java:17)
    at com.ninjadynamics.python.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5461)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
 

wonder

Expert
Licensed User
Longtime User
Many thanks for your work , i just test your python test then i got this error
Oops, it seems that I forgot to clarify on the first post, that you'll need the python zip files found in the Demo Project.
Please copy them to your Files folder and give it another try.

EDIT: First post updated.
 
Last edited:
Top