Tôi có thể thực thi mã Python đơn giản như thế nào trong Chế độ Org 'Org?Chế độ Orac Org: Thực thi mã python đơn giản
Ví dụ đầu tiên hoạt động tốt, tuy nhiên tôi không thể làm cho nó đưa cho tôi kết quả của phép tính đơn giản nhất:
; works
#+begin_src python
def foo(x):
if x>0:
return x+10
else:
return x-1
return foo(50)
#+end_src
#+RESULTS:
: 60
; does not work
#+begin_src python
1+1
#+end_src
#+RESULTS:
: None
; does not work
#+begin_src python
print(1+1)
#+end_src
#+RESULTS:
: None
tôi thiết lập Org Chế độ sử dụng các dòng sau:
;; enable python for in-buffer evaluation
(org-babel-do-load-languages
'org-babel-load-languages
'((python . t)))
;; all python code be safe
(defun my-org-confirm-babel-evaluate (lang body)
(not (string= lang "python")))
(setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
Thử 'return print (1 + 1)' có lẽ? Chữ 'return' này có vẻ" thừa "trong mã ban đầu (bên ngoài hàm). – PascalVKooten