From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: Re: [babel] passing tables to python source blocks Date: Fri, 26 Mar 2010 20:14:17 -0400 Message-ID: <87vdciboyu.fsf@stats.ox.ac.uk> References: <87wrwyhiay.fsf@cuma.i-did-not-set--mail-host-address--so-tickle-me> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NvJfZ-0008U0-1q for emacs-orgmode@gnu.org; Fri, 26 Mar 2010 20:14:29 -0400 Received: from [140.186.70.92] (port=47538 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NvJfX-0008Ts-Lx for emacs-orgmode@gnu.org; Fri, 26 Mar 2010 20:14:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NvJfU-0004AJ-R1 for emacs-orgmode@gnu.org; Fri, 26 Mar 2010 20:14:27 -0400 Received: from markov.stats.ox.ac.uk ([163.1.210.1]:33767) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NvJfU-0004A0-JI for emacs-orgmode@gnu.org; Fri, 26 Mar 2010 20:14:24 -0400 In-Reply-To: <87wrwyhiay.fsf@cuma.i-did-not-set--mail-host-address--so-tickle-me> (Maurizio Vitale's message of "Fri, 26 Mar 2010 17:41:41 -0400") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: maurizio.vitale@polymath-solutions.com Cc: emacs-orgmode@gnu.org Maurizio Vitale writes: > Hi, > I get the following error when passing a table containing a line > separator (like mounts below). It looks like the table is first exported > to ASCII (and the horizontal line mapped to hline), but hline is not > known in python-land. Would it be possible to discard it instead? Hi Maurizio, Yes. I've put a patch below which is a quick hack discarding the 'hline for python. But I don't propose we apply it to the public version. The question is whether we merely discard the hline or in fact discard the entire header line as well. I think the correct solution is to make python (and other languages) interpret the :colnames argument appropriately (currently only R pays attention to this). I would welcome any views on how this should be done consistently across languages, given that some languages (e.g. R) have a concept of column and row names for tabular data structures while other languages do not. We need to specify the behaviour for tables being sent to languages, and for tables being received from languages. Julien Barnier has been working on adding :rownames for R recently. I posted a reply to Julien yesterday http://permalink.gmane.org/gmane.emacs.orgmode/23324 containing an org file for testing :colnames and :rownames. Dan --8<---------------cut here---------------start------------->8--- diff --git a/contrib/babel/lisp/langs/org-babel-python.el b/contrib/babel/lisp/langs/org-babel-python.el index 7e938bb..eb37732 100644 --- a/contrib/babel/lisp/langs/org-babel-python.el +++ b/contrib/babel/lisp/langs/org-babel-python.el @@ -87,7 +87,7 @@ called by `org-babel-execute-src-block'." "Convert an elisp var into a string of python source code specifying a var of the same value." (if (listp var) - (concat "[" (mapconcat #'org-babel-python-var-to-python var ", ") "]") + (concat "[" (mapconcat #'org-babel-python-var-to-python (delq 'hline var) ", ") "]") (format "%S" var))) (defun org-babel-python-table-or-string (results) --8<---------------cut here---------------end--------------->8--- > Thanks, > > Maurizio > > #+results: partition-ids-sacred > | sda1 | 44d8b686-253d-4d84-bc1d-6241256e7a48 | > | sda5 | 4d061415-21e4-4419-b8a5-3fff37090e5f | > | sdd3 | 6404fb2a-c30f-475c-b386-89c98d5cb3c6 | > | sdd5 | 9b072633-a66d-4870-8617-d955c535782f | > | md0 | a24470a7-1d7e-4938-9f09-ab11cdb78bc3 | > | sdd1 | dfcb40e1-9e2f-485e-8897-94ee0458c5e7 | > > #+tblname: mounts > | Device | Mount | type | options | dump | pass | > |--------+---------------------+------+----------+------+------| > | sdd1 | /library | ext3 | defaults | 0 | 0 | > | sdd3 | /backup | ext2 | defaults | 0 | 0 | > | md0 | /home/mav/workspace | ext3 | defaults | 0 | 0 | > > #+source mtab > #+begin_src python :var mounts=mounts :var ids=partition-ids-sacred :results output > print mounts > #+end_src > > #+results: > : Traceback (most recent call last): > : File "", line 1, in > : NameError: name 'hline' is not defined > > > > > > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode