How do I construct a script such that given a code block, it will return and display rich output like that of a cell of a Jupyter notebook? For example, is there a way to get the output section of the ipynb file given the code for the cell?
Asked
Active
Viewed 63 times
0
-
Based on what you wrote in the [other comment](https://stackoverflow.com/questions/74683522/how-do-i-construct-a-python-function-where-the-input-in-python-code-and-output-i/74694087?noredirect=1#comment132897337_74694087) I don't think 'build' is the proper term to be in your question here? But maybe it is? You'd have to describe better your goal. And your starting points. Are you starting from a pre-run notebook for the case you describe? In that case, getting the HTML is easy because it's already in the notebook. You can use nbformat to simply parse it out easily. – Wayne Feb 01 '23 at 20:38
-
I suspect though based on your other topic, you are trying to start with just the code? In that case I'd suspect your example isn't very good because you need to account for a way to provide the CSV file too? Which you haven't described. Maybe make your example self-contained so the data to make the dataframe is in the code, too? Something as simple as `df = pd.DataFrame(np.random.randn(10, 4))`? Or are you looking to code from C++ from scratch all you'd need to do this? And that is why you say build? – Wayne Feb 01 '23 at 20:41
1 Answers
0
I ended up creating a ipynb, execute it using nbconvert.preprocessors.ExecutePreprocessor
, and then get the output. Thank you Wayne for the answer. See more at How do I construct a python function where the input in python code and output is ipython rich output (in HTML)?

Julian Chu
- 1,790
- 2
- 7
- 12