Jupyter laptop cell number in cell

Can a cell number in a cell be used as a variable?

For example: I try to create png with different settings every time I run a cell (to see which result I like best). I want to save all the outputs without having to change the file name, and also every time (since it is easy to forget).

I thought it was useful to use the cell number as a variable in my file name. Is it possible?

+5
source share
1 answer

I do not know about the execution number, but if for each execution of the same cell you only need a different number, you can use environment variables through IPython Magics , in particular the magic of %env . Try the following:

  • Initialize the environment variable in one cell:

     %env count=0 
  • In another cell, the following code will increment this variable after each execution:

     var = %env count var = int(var) + 1 %env count=$var print(var) 
0
source

Source: https://habr.com/ru/post/1263099/


All Articles