lisp怎么获取python输出


#1

lisp怎么获取python的输出呢?

比如我现在想获取下面的输出,保存到lisp的变量里,类型是list

py -c "import sys; print sys.path"

怎么做比较好?python的list怎么转化成lisp的list,通过字符串处理吗?


#2

字符串在 Python 和 Emacs Lisp 中的写法有差异,可以通过 JSON

(let ((json-array-type 'list))
  (json-read-from-string
   (shell-command-to-string
    "python -c 'import sys, json; print(json.dumps(sys.path))'")))
;; =>
(""
 "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip"
 "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7"
 "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin"
 "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac"
 "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages"
 "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk"
 "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old"
 "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload")