clj-python / libpython-clj

Python bindings for Clojure
Eclipse Public License 2.0
1.06k stars 69 forks source link

`run-simple-string` doesn't return `:result` keyword #129

Closed cloojure closed 3 years ago

cloojure commented 3 years ago

Tried a test:

(py/run-simple-string "(2 + 3)") => 
{:globals
 {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>},
 :locals
 {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>}}
jjtolton commented 3 years ago

What is the expected behavior here? Sounds like you're expecting a :result key?

jjtolton commented 3 years ago

Ah, I see. The documentation says there should be a :result. This is no longer the case, we'll update the docstring.

If you're looking for a result, you need to use the interop directly. As an example:

(require '[libpython-clj.requre :refer [require-python import-python]])
(require-python 'operator)
;;=> :ok
(operator/add 2 3) 
;;=> 5
jjtolton commented 3 years ago

@cloojure if you're encountering any issues with getting started, please feel free to stop by the Zulip chat (https://clojurians.zulipchat.com/#narrow/stream/215609-libpython-clj-dev) or continue to message here!

cloojure commented 3 years ago

OK, cool. Thanks for the tip about operator/add I was wondering how to do that! Alan

On Mon, Oct 19, 2020 at 5:29 PM J.J. Tolton notifications@github.com wrote:

Ah, I see. The documentation says there should be a :result. This is no longer the case, we'll update the docstring.

If you're looking for a result, you need to use the interop directly. As an example:

(require '[libpython-clj.requre :refer [require-python import-python]]) (require-python 'operator);;=> :ok (operator/add 2 3) ;;=> 5

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/clj-python/libpython-clj/issues/129#issuecomment-712514793, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABWBOB5LSINKZOEW6ABLRHTSLTKVFANCNFSM4SXBXSRA .

cnuernber commented 3 years ago

I couldn't figure out how to get the last result left on the stack. I really would like it to just return the result that was left on the stack but regardless the documentation was incorrect (fixed now, thank to JTolton). Thanks for bringing this up!