1

i am not a python devloper but i can fugre bits and peices out... as a multi devloper im faced with code in all formats :: so i often forget a lot!! so i need help to be able to execute code on a jupiter notebool from a python app and return the value of the executed cell: so i would like to be able to send a few cells as a lest then execute them interactivly ie : cell 1-5 then cell 8 ... returning the results : I understand that some how to go the Ipython route for this ? but cannot fiugure it out can yuou help ?

Obiously i know how to use jupiter notebook but i dont want to use it directly , but programatically :

I need to be able to run a cell from a python script on the ipython kernal and return the output from the function sent < hence the function would be sent as a string to the ipython(ikernal) or jupyter_client and return the value , pass/ fail / output ... verbose on/off....

so to use the jupyter_client to even execute a script on the operating system using a magic command sending it to the jupyter client to return the result could be the output from an installation via pip or even a project directory listing....but also it can be a code output , hence also it could be a custom environmnet ( loaed in a virtual jupiter notebook, items imported , code executed , result returned) ...in a clean environment (could be volitile and destructable hence not held or kepy , as well as could be a prewritten jupyter notebook file , or simply a python script?).. today we recive a lot of mixed scripts containing markdown and code and often we do not have time to sift through documents or keep writing mad funcitons to extract specific code fragments from code .. but ipython can handle these mised code snipptes of markdown and pycode or other lisp/rust/r/ etc which can all be ru on a note book ... hence from a python app r code can be executed in a cell and its output returned to the original python app ! hence the requirement for this funcitonality as it enables mulit code develoopment strategeies :

Today this is also used in fucntion calling for llm large lang models etc !

it will also open the understanding of how to be utilizing the ipython from a windows console app (.net) (VB.NET) - so i can use python in my prime programing languge VB.NET(utilizing python.net) ...

Sorry for the long post but its important to fully outline my quesion :

im totally confused which item to be using .... Jupiter client ? pyNotebook, ikernal, ipython ? the api information is confusions

6
  • 1
    Perhaps the easiest, direct way to use Python code to execute code cells or entire notebooks is to use nbformat to make content you want. You can even use nbformat to copy specific cells, see here. I often use nbformat to place code into cells using nbformat. Because it is Python, you can use all sorts of ability in the process. Then you run the produced notebooks with either jupyter nbconvert or , my preference, jupytext. ... Commented Jun 2, 2024 at 16:05
  • <continued> Like so, os.system("jupytext --execute my_notebook.ipynb"). See ... here for more details about executing .ipynb files from the command line. There are other more complex things you can do with running kernels but to manage things directly what I've outlined is convenient and easy to troubleshoot. Commented Jun 2, 2024 at 16:05
  • I think this question needs some editing and a lot more focus. Commented Jun 2, 2024 at 17:16
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Jun 2, 2024 at 20:09
  • the focus is to run code using ipykernal or jupiter_client!>> from a python code: so , that i can collect my responses from my chatbot and execute them on my system ... using a cell in jupiter notebook or ipython and return the result to the model : again because a jupiter cell can execute both bash and code! so the function sent ot the cell will be the same despite the call ... ie i will sent the contents ie the string to be executed in the cell and its output returned ! Commented Jun 4, 2024 at 5:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.