I'm using emacs 25.2.1 with spacemacs and scimax and trying to create a jupyter-like notebook. After some experimenting, I'm confused by the output I get from the :results output
tag from the final src block:
#+name: OOP
#+BEGIN_SRC elisp :results silent :session OOP
(pyvenv-activate "~/Desktop/py2_venv")
#+END_SRC
#+BEGIN_SRC ipython :session OOP :results silent
class Dog():
def __init__(self, breed, name, spots):
self.breed = breed
self.name = name
#expect boolean true/false
self.spots = spots
#+END_SRC
#+BEGIN_SRC ipython :session OOP :results output
my_dog = Dog(breed='lab', name='Sammy', spots='False')
print(type(my_dog))
print(my_dog.breed)
my_dog.name
my_dog.spots
#+END_SRC
#+RESULTS:
**:RESULTS:
# Out[23]:
# output
<class '__main__.Dog'>
lab
# text/plain
: 'False'**
:END:
It's my understanding that all output should be displayed with the output
option in session
mode. Additionally I shouldn't need to use print()
. I'm confused why my_dog.name
is missing from output, but my_dog.spots
is not. Any ideas what I'm missing?
:results output
gives back the stdin, which will be the print output.
If you use :results value
or :results value raw
you will receive the last evaluation and not the side effect :
#+BEGIN_SRC ipython :session OOP :results value
my_dog = Dog(breed='lab', name='Sammy', spots='False')
print(type(my_dog))
print(my_dog.breed)
my_dog.name
my_dog.spots
#+END_SRC
In order to get both evaluations you will need to type a bit more python.
Have a look at :
https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-python.html
also the following answer in Emacs SE: https://emacs.stackexchange.com/a/45121/17548