* babel - python question
@ 2013-07-05 12:44 Rustom Mody
2013-07-05 14:28 ` Eric Schulte
0 siblings, 1 reply; 2+ messages in thread
From: Rustom Mody @ 2013-07-05 12:44 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 538 bytes --]
[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?
Also the results changed to output does not change the behavior
[-- Attachment #2: Type: text/html, Size: 763 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: babel - python question
2013-07-05 12:44 babel - python question Rustom Mody
@ 2013-07-05 14:28 ` Eric Schulte
0 siblings, 0 replies; 2+ messages in thread
From: Eric Schulte @ 2013-07-05 14:28 UTC (permalink / raw)
To: Rustom Mody; +Cc: emacs-orgmode
Rustom Mody <rustompmody@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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-07-05 14:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-05 12:44 babel - python question Rustom Mody
2013-07-05 14:28 ` Eric Schulte
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).