B4A Library NinjaPython - Use Python Scripts in B4A

wonder

Expert
Licensed User
Longtime User
No issues here, I successfully imported the Regex module and displayed its contents.
Tested on two different devices (PC and Tablet).

Memu PC Emulator (x86):

NVIDIA Shield Tablet K1 (ARM):

Do you have the same issue with the Demo project?
 

Husam

Member
Licensed User
No issues here, I successfully imported the Regex module and displayed its contents.
Tested on two different devices (PC and Tablet).

now its work, i just changed the compilation mode from debug to release

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
[NinjaPython] ARM CPU detected
[NinjaPython] Python 2.7.9 was successfuly installed in: /data/user/0/b4a.example/files
[NinjaPython] Initialized
[NinjaPython] In [1]:
SayHello('world')
[NinjaPython] Out[1]:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'SayHello' is not defined
[NinjaPython] Terminated
** Activity (main) Resume **
 

wonder

Expert
Licensed User
Longtime User
Glad to hear that!

Regarding your Python code, note that you are calling a function that was not previously declared. You need to define SayHello().
B4X:
def SayHello(name):
    print "Hello, " + name + "!"

SayHello("world")
 

wonder

Expert
Licensed User
Longtime User
Here's an idea:
B4X:
'You can keep your functions on a separate file, without executable code
Dim myPythonFunctions = File.ReadString(File.DirAssets, "myFunctions.py") As String

'Start the interpreter
Py.Initialize

'Load your functions into memory
Py.Exec(myPythonFunctions)
...
...
'Call a specific function whenever you want
Py.Exec("SayHello('World')")
Py.Exec("SayHello('Moon')")
Py.Exec("SayHello('Mars')")

'Finalize destroys the interpreter object, meaning
'your functions are no longer in memory
Py.Finalize
 

Q Candiani

Member
Licensed User
Longtime User
Great work! I interest to use de psycopg2 library to connect to a postgresql database from my app. Is there any way to use it? I think it would be very powerful tool. Thank you very much
 

wonder

Expert
Licensed User
Longtime User
Hi!! I'm back from the dead!

Is this library only for B4A, or will it work in B4J?

Nope, it's B4A only. On the PC you could just use regular Python, right?
 

Cableguy

Expert
Licensed User
Longtime User
Hi!! I'm back from the dead!

You never die while someone still remembers you!


Nope, it's B4A only. On the PC you could just use regular Python, right?

Just out of curiosity, how could python be integrated in a b4j project?
 

DonManfred

Expert
Licensed User
Longtime User
Just out of curiosity, how could python be integrated in a b4j project?
B4X:
Sub StartTest
    Dim shl As Shell
    shl.Initialize("shl","python",Array("/.../.../test.py"))
    shl.RunWithOutputEvents(-1)
End Sub

Sub shl_StdOut (Buffer() As Byte, Length As Int)
    Dim Output As String = BytesToString(Buffer,0,Length,"UTF-8")
    Log(Output)
End Sub

Sub shl_StdErr (Buffer() As Byte, Length As Int)
    Dim Output As String = BytesToString(Buffer,0,Length,"UTF-8")
    Log(Output)
End Sub
 

wonder

Expert
Licensed User
Longtime User
Hey Ilan! I'm doing alright, thanks!! How about you?
Well, I barely have time to dedicate myself to B4X nowadays, due to my current schedule.

I'm still working on some of my stuff, here and there.
 

ilan

Expert
Licensed User
Longtime User
I'm still working on some of my stuff, here and there.

Please dont abandon your 2d knight game. You must finish it. It is a master piece.

How about you

I am fine thanx. I also have very little time for coding. I switch job 1 month ago and i have lot of work in my new job so less time for my b4x projects but right now i am working on a b4a app that will make me rich.

(If i would get 1$ for everytime i thought this will be the one i really would be already rich)
 

sorex

Expert
Licensed User
Longtime User
are you still into CNC? or did you enter the world of IT as profession?
 

wonder

Expert
Licensed User
Longtime User
Please dont abandon your 2d knight game. You must finish it. It is a master piece.
I won't! I've been learning GLSL and experimenting with shaders!

i am working on a b4a app that will make me rich
Ahahah!!! I really hope that day will come!!!


On a side note, this thread is about NinjaPython, so better if we can get back on topic before Erel gets mad.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…