...
Yes, I think we do want a version of this for python and ruby et al.
In
your example, the filename is created in python. I suggest doing it
slightly differently, something like this.
#+srcname: fileoutput
#+begin_src python :file outfile.txt
def savetofile(result, filename):
with open(filename, 'w') as f:
f.write(str(result))
savetofile(78, 'outfile.txt')
55
#+end_src
#+resname: fileoutput
[[file:outfile.txt]]
This functionality is now available for ruby & python in branch
ded-babel of git://repo.or.cz/org-mode/babel.git.
So here, if you specify :file <filepath> ruby/python blindly outputs a
link to <filepath>, regardless of the contents of the
code. Responsibility for creating useful contents of <filepath> lies
with the code. Notice that with this you have to specify the output
file
twice: once as an org-babel directive, and once in the python code.
This
is in contrast to the graphics languages (dot, ditaa, asymptote),
where
the results *automatically* get sent to the file specified by :file.
The
same is also true now for graphical output from R.
The difference with python, ruby et al is that they might create file
output in a variety of ways which we can't anticipate, so we can't
automatically send output to the file. In contrast, the graphics
language *always* create file output and always do it in the same
way. [And in R it is possible to divert all graphical output to
file] A
possible extension of the above might be to use a "magic variable" so
that a python variable is created e.g. __org_babel_output_file__ that
always holds a string corresponding to the file specified by :file.
Eric
may have further ideas / views here.
...