ipython / ipython/ipython

autoreload kills variables

Offen
#12,386 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
16.8k
Forks
4.5k
Ø Merge
1 T. 2 Std.
Gemergte PRs (30 T.)
6

Beschreibung

[As recommended](https://ipython.readthedocs.io/en/stable/config/extensions/autoreload.html) I added
```
%load_ext autoreload
%autoreload 2
```
to my notebook and now, indeed, the modules are automatically reloaded.

Alas, I have
```
try: # https://docs.python.org/library/importlib.html
rala_all # reload will not reset rala_all
except NameError:
rala_all = {}
```
in my module. It did work before using [`importlib`](https://docs.python.org/library/importlib.html), but, with [`autoreload`](https://ipython.readthedocs.io/en/stable/config/extensions/autoreload.html) I see `rala_all` being reset (to an empty dictionary) every time the module is reloaded.

Is there a way to avoid this? I want `rala_all` to survive (auto)reload.
(also [asked](https://stackoverflow.com/q/62204805/850781)).

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.