Skip to main content
added 31 characters in body
Source Link
Flint
  • 339
  • 2
  • 15
#+Name: Scores #+BEGIN_SRC python :results output raw from random import randint li ='''Max Charlie Cooper Buddy Jack Rocky Oliver Bear Duke Tucker'''.split() print( "|{0:8s}| {1:3s} | {2:3s} | {3:3s} |".format( "Name","str","agi","int" )) for f in li: print("|{0:8s}| {1:3d} | {2:3d} | {3:3d} |".format( *( [f]+[randint(0,20) for x in range(3)]) )) #+END_SRC #+Call: Scores() 
#+Name: Scores #+BEGIN_SRC python :results output raw from random import randint li ='''Max Charlie Cooper Buddy Jack Rocky Oliver Bear Duke Tucker'''.split() print( "|{0:8s}| {1:3s} | {2:3s} | {3:3s} |".format( "Name","str","agi","int" )) for f in li: print("|{0:8s}| {1:3d} | {2:3d} | {3:3d} |".format( *( [f]+[randint(0,20) for x in range(3)]) )) #+END_SRC #+Call: Scores() 
#+Name: Scores #+BEGIN_SRC python :results output raw from random import randint li ='''Max Charlie Cooper Buddy Jack Rocky Oliver Bear Duke Tucker'''.split() print( "|{0:8s}| {1:3s} | {2:3s} | {3:3s} |".format( "Name","str","agi","int" )) for f in li: print("|{0:8s}| {1:3d} | {2:3d} | {3:3d} |".format( *( [f]+[randint(0,20) for x in range(3)]) )) #+END_SRC #+Call: Scores() 
#+Name: Scores #+BEGIN_SRC python :results output raw from random import randint li ='''Max Charlie Cooper Buddy Jack Rocky Oliver Bear Duke Tucker'''.split() print( "|{0:8s}| {1:3s} | {2:3s} | {3:3s} |".format( "Name","str","agi","int" )) for f in li: print("|{0:8s}| {1:3d} | {2:3d} | {3:3d} |".format( *( [f]+[randint(0,20) for x in range(3)]) )) #+END_SRC #+Call: Scores() 
edited title
Link
Flint
  • 339
  • 2
  • 15

org-mode : add an attribute or a property to a the result of a call

Source Link
Flint
  • 339
  • 2
  • 15

org-mode : add attribute or property to a the result of a call

Let suppose our program output many formatted tables.

For instance :

#+Name: Scores #+BEGIN_SRC python :results output raw from random import randint li ='''Max Charlie Cooper Buddy Jack Rocky Oliver Bear Duke Tucker'''.split() print( "|{0:8s}| {1:3s} | {2:3s} | {3:3s} |".format( "Name","str","agi","int" )) for f in li: print("|{0:8s}| {1:3d} | {2:3d} | {3:3d} |".format( *( [f]+[randint(0,20) for x in range(3)]) )) #+END_SRC #+Call: Scores() 

The evaluation of the code block will produce an output similar to this

#+RESULTS: | Name | str | agi | int | | Max | 17 | 15 | 16 | | Charlie | 2 | 5 | 19 | | Cooper | 3 | 5 | 5 | | Buddy | 9 | 6 | 9 | | Jack | 11 | 14 | 19 | | Rocky | 19 | 1 | 2 | | Oliver | 5 | 17 | 5 | | Bear | 0 | 17 | 17 | | Duke | 16 | 8 | 19 | | Tucker | 14 | 13 | 9 | 

When exporting, the #+CALL is evaluated, and its results gets exported.

Question: how to automate the insertion of something like

#+ATTR_LaTeX: :center nil :align |p{5cm}|l|l|l| 

on top of the table in the results section ?

Any proposal is welcome, be it by outputting by value, hooking the export, creating a latex header... or indicating any appropriate org function.