B4J Question [Solved]How to code William's PyBridge example

Theera

Expert
Licensed User
Longtime User
Refer to this ,I 've coded as following William's example which is attached file. I have still error codea after clicked the button.
My the lastest I have edited,but I have still error code.
B4X:
Dim opt As PyOptions = Py.CreateOptions(File.Combine(File.DirApp, "C:\Python/python310/python.exe"))
 

Attachments

  • Project.zip
    3.5 KB · Views: 38
Last edited:
Solution
Use this code:
B4X:
Private Sub Fibonacci(n As Int) As PyWrapper
    Dim Code As String = $"
#python code here

#Fibonacci numbers module
def Fibonacci(n):
    result=[]
    a,b=0,1
    while a<n:
        result.append(a)
        a,b=b,a+b    
    return result
"$
    Return Py.RunCode("Fibonacci", Array(n), Code)
End Sub

I've reset the indentation and set it again.

Theera

Expert
Licensed User
Longtime User
Thank you all of you for replies to me.
 
Upvote 0

abonvici

Member
Licensed User
Hi al,
instead of using a string to contians the python code, is it possibile to use file and read the script from file, so to have a script of whatever complexity?
I have used python for meny years , nad i think that pybridge is a fantastic enhancement.
Thanks a lot
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Hi al,
instead of using a string to contians the python code, is it possibile to use file and read the script from file, so to have a script of whatever complexity?
Yes, you can read code from file
B4X:
Py.RunCode("Fibonacci", Array(n), File.ReadString(...))
 
Upvote 0
Top