简体   繁体   中英

In Jupyter notebook/lab, how can I automatically reset variables on exit?

I have a jupyter notebook containing sensitive data that I would like to not be cached inside the notebook. This would avoid jupyter's tendency to mix data and code.

In a notebook I can reset all variables using

%reset

Is there any way to run this automatically on exit, or on shutdown of the notebook or server?

Or is there a command-line script that could be run over a .ipynb , eg in a nightly cron job, to purge the file of stored variables (or - even better - only certain variables)?

Thanks!

nbclean allows some fairly complex customization on what gets cleaned and altered in the resulting notebook. You could do cron job with a script running that on your schedule. Or use Github actions to trigger upon actions such as push.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM