Python Command Line Interpreter not recognizing updated changes in my code? -
this question has answer here:
i'm using atom text editor write code in, , importing python 3.4 command line interpreter. if make mistake in code , have make fix, i'm unable see changes reflected in interpreter until close , re-open it. happens if re-import file. have cache need clear? how 1 see code changes in interpreter without closing it?
when load python module in interpreter, reads imported code once, caches code later use. means if make changes module, you'll have tell interpreter reload content. pretty easy do:
>> import foo # crystallizes foo code in interpreter state in @ time of import >> # [updates made foo code] >> import importlib >> importlib.reload(foo)
that should it!
[note: importlib new in python 3.4 . before that, imp had same functionality. in python 2 reload() function part of default namespace.]
Comments
Post a Comment