Rustom Mody <rustompm...@gmail.com> writes: > [Complete babel noob here] > > Following the babel doc > http://orgmode.org/worg/org-contrib/babel/intro.html#library-of-babel > > I wrote this > > * Head > #+name: ppp :results value > #+begin_src python > import time > print("Hello, today's date is %s" % time.ctime()) > print('Two plus two is') > return 2 + 2 > #+end_src > > Hit C-c C-c > > and got a new block > > #+RESULTS: > : 4 > > > I am mystified! > In python a top level return gives a syntax error. > Here it works. Is some secret function being created? >
Yes, when returning a value, the code block itself becomes a function. > > Also the results changed to output does not change the behavior Not true, however you need to put the header arguments on the begin_src line or on a #+headers line (not on the #+name line). Also, try to mix :results output and "return 2 + 2", and you should find the error you expected earlier. Best, #+begin_src python :results value import time print("Hello, today's date is %s" % time.ctime()) print('Two plus two is') return 2 + 2 #+end_src #+RESULTS: : 4 #+begin_src python :results output import time print("Hello, today's date is %s" % time.ctime()) print('Two plus two is') #+end_src #+RESULTS: : Hello, today's date is Fri Jul 5 08:27:02 2013 : Two plus two is -- Eric Schulte http://cs.unm.edu/~eschulte