I’m afraid I don’t understand something basic. I use python interactively with IPython and I’m running more or less the following script (VPP is a module I wrote with class VPP and class Forecast, they both extend from object).
import os
import numpy as np
from VPPP import VPP, Forecast
setup = False
single_run = True
if setup:
vpp = VPP(foo=foo, bar=bar, ...)
forecast = Forecast('my_filename')
mapping = {'Forecast': 'PConInput.ys[xxx]', 'Price': 'tariffInput.ys[xxx]'}
if single_run:
fnext = forecast.predict(startday=146, nb_days=2)
vpp.adapt_forecasts(fnext, mapping)
vpp.optimize()
I have the flags setup and single_run because the instantiation of vpp takes about 2 minutes, and I want to use the same vpp later in single run with different parameters.
When I run the script with both flags True, all is fine. However, when I run again with setup = False I get an errormessage: NameError: name ‘forecast’ is not defined (caused by fnext = ...). However, typing directly in the IPython shell, all instances are known and all commands work fine.
Is this an IPython issue? How can I avoid the instantiation of my vpp object everytime I want to run my script?
Thanks on beforehand for your answers.
Roel
Do you run the script using the IPython
%runcommand?In that case use:
-iruns the file in IPython’s namespace (instead of an empty one).For documentation, type
%run?<ENTER>in IPython.