Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is iPython notebook interpreting commented out lines?

This question is not about a specific error---the error arrises because I'm using matplotlib's tight_layout incorrectly.

I want to know why iPython is interpreting a line of code that I have commented out--or, rather, under what circumstances this is expected to happen (i.e., I need to relaunch the kernel, or whatever).

The error seems to persist, in spite of the fact that I re-executed the relevant imports.

Code:

import forecasting_report.analyze as fcst_rprt
analysis = fcst_rprt.ForecastingReport()
analysis.analyze()
results = analysis.user_dict

Error says:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-a62e6e8717be> in <module>()
      1 analysis = fcst_rprt.ForecastingReport()
----> 2 analysis.analyze()
      3 results = analysis.user_dict

/Users/[...]/ForecastingReport/forecasting_report/analyze.py in analyze(self)  
     44         self.breakdown = help.breakdown(self.user_dict)
---> 45         #plots.plot_breakdown(self.breakdown, self.path)
     46 
     47     def write_results(self):

<Error Stack continues>

Note:

A perfectly fine answer is : "That's just not the way it works". To be sure, I haven't tried to reproduce this error at the command line, so it just may be my ignorance of the Python interpreter.

like image 240
BenDundee Avatar asked May 24 '26 10:05

BenDundee


2 Answers

Python will only initialise an imported module once, further calls to import will have no effect, even if the module has been modified since being read.

To reload a module, use the builtin function reload on the already imported module object, e.g.:

import mymodule

# ...later...
reload(mymodule)
like image 144
Dave Challis Avatar answered May 26 '26 22:05

Dave Challis


try

%load_ext autoreload
%autoreload 2

which should work with ipython terminal, i not sure if it works in ipython notebook. You can view help through autoreload? and this post: Autoreload of modules in IPython

like image 42
Shijing Lv Avatar answered May 27 '26 00:05

Shijing Lv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!