You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PythonCall not working in Jupyter Notebook in VSCode #601
pyexec always returns nothing when called like that, it would have been the same in the REPL. In the REPL it probably just looked like it returned something because you print the answer inside fib.
To extract values you can pass a named tuple type specifying what to keep, like
Thanks for your suggestion by using pyexec, nevertheless, the following code still does not work as I get the following error message:
cannot convert this Python 'NoneType' to a Julia 'BigInt'
Did I do something wrong. Also I am confused why you suggest to use BigInt as I taught Float64 would be more appropriate.
Many thanks for your kind help,
Joseph
functionPYTHON_2_JULIA(x)
fib(x) =pyexec(@NamedTuple{ans::BigInt},"""def fib(n): a, b = 0, 1 while a < n: print(a, end=' ') a, b = b, a+b print()ans = fib(y)""", Main, (y=x,))
C =fib(x)
println(C)
return C
end
Activity
cjdoris commentedon Apr 9, 2025
pyexecalways returnsnothingwhen called like that, it would have been the same in the REPL. In the REPL it probably just looked like it returned something because you print the answer insidefib.To extract values you can pass a named tuple type specifying what to keep, like
Also see the
@pyexecmacro which makes this a bit easier.AquaPore commentedon Apr 9, 2025
Hi Christopher,
A great thanks for your kind help.
Thanks for your suggestion by using pyexec, nevertheless, the following code still does not work as I get the following error message:
Did I do something wrong. Also I am confused why you suggest to use
BigIntas I taughtFloat64would be more appropriate.Many thanks for your kind help,
Joseph
AquaPore commentedon Apr 9, 2025
I found an alternative solution by using as you suggested by using ** PythonCall.@PYEXEC**
To run it:
This gives as expected
cjdoris commentedon Apr 9, 2025
Glad it's working now, I'll close the issue as resolved.
BTW the reason the previous
fibwasn't working is because it didn't actually return anything.AquaPore commentedon Apr 14, 2025
Thanks @cjdoris , the idea is to wrap up some pyflwdir python package. Would you know how to call for e.g. numpy package into the example?
Thanks for any help you may provide.