bendudson / py4cl

Call python from Common Lisp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unicode dictionary keys not converting

vxe opened this issue · comments

n00b CL/python user here, am I doing something wrong here?

> (defvar test-map (py4cl:python-eval "{'pizza': 3}"))
> (alexandria:hash-table-keys (py4cl:python-eval "{'pizza': 3}"))
("pizza")

>  (defvar test-map-unicode (py4cl:python-eval "{u'pizza': 3}"))
> (alexandria:hash-table-keys test-map-unicode)
(#S(PY4CL::PYTHON-OBJECT :TYPE "<type 'unicode'>" :HANDLE 401921))

Thanks for reporting.

I, too, am not too familiar with python; but, in this case, it works with python3 and not with python2. You can try setting *python-command*:

> (py4cl:python-stop) ; close the previous python process
> (setq py4cl:*python-command* "python3")
"python3"

There are differences between how unicode is handled in python2 vs python3. This might be of help.

I'm unsure how this should be handled - should it be left as it is? Should it be converted to CL string? Or some other way? I'll wait for @bendudson to reply. Or if you have any suggestions, feel free to leave so.

You can also go through some py4cl documentation - though that is for a version yet to be finalized. Quite a number of visible changes are due to name replacement from python- to py.

Hi! I've added a small change and test which fixes your example in PR #19 for both python 2 and python 3.
Unfortunately Unicode in python 2 is a bit of a mess, and passing unicode characters to/from python2 doesn't work yet. It works for me in python3 though. Sorry, I'm not sure how to fix this properly for python2, so for now please use python3 if you can.

switching to python3 was the answer for me

still in favor of the PR however as new users coming from python2.7 will likely get tripped up on this when consuming json from the standard library json module which,afaict, only outputs dictionaries with unicode keys

Closing this: Partly fixed in #19, using python 3 recommended.