emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Sharing variables between source blocks without session


From: Loris Bennett
Subject: Sharing variables between source blocks without session
Date: Tue, 16 Mar 2021 09:56:13 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

Hi,

I have a 'sh' source block which produces a table which I then want to
plot with a 'python' source block:

#+NAME: code;raw_data
#+HEADER: :var user="loris"
#+BEGIN_SRC sh
  ps -u loris -o etimes=
#+END_SRC                                                                       
                                                                                
                                                 

#+NAME: tab;raw_data
#+RESULTS: code;raw_data...

#+HEADER: :var df=tab;raw_data
#+HEADER: :var user="loris"
#+BEGIN_SRC python :results file :var f="process_times.pdf"
  import numpy as np
  import matplotlib.pyplot as plt
  # flatten list
  x = [item for sublist in df for item in sublist]
  plt.hist(x, bins=10)
  plt.xlabel("time [s]")
  plt.ylabel("number of processes")
  plt.title("user: " + user)
  plt.savefig(f) 
  return f
#+END_SRC

How can I avoid having to declare the variable 'user' for both blocks?

Cheers,

Loris

-- 
This signature is currently under construction.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]