Python3.8——什么代替了';与';陈述

Python3.8——什么代替了';与';陈述,python,try-catch,Python,Try Catch,无需选择“with”语句 只在程序的第一行添加“fromfutureimport with_statement”,然后它就可以工作了请澄清您的问题?请再添加一点说明。我想捕捉当scipy无法完全曲线拟合数据以防止程序关闭时发生的错误。但是我的python不支持with语句和send error。 for i in range(0,len(periods)): coeffs = [] for j in range(periods[i],len(prices)-p

无需选择“with”语句
只在程序的第一行添加“fromfutureimport with_statement”,然后它就可以工作了

请澄清您的问题?请再添加一点说明。我想捕捉当scipy无法完全曲线拟合数据以防止程序关闭时发生的错误。但是我的python不支持with语句和send error。
for i in range(0,len(periods)):

        coeffs = []

        for j in range(periods[i],len(prices)-periods[i]):

            x = np.arange(0,periods[i])
            y = detrended.iloc[j-periods[i]:j



  with warnings.catch_warnings():
            warnings.simplefilter('error',OptimizeWarning)

            try:
                res = scipy.optimize.curve_fit(fseries,x,y)

            except (RuntimeError, OptimizeWarning):
                res = np.empty(1,4)
                res[0,:] = np.NAN

            if plot == True:
                xt = np.linspace(0,periods[i],100)
                yt = fseries(xt,res[0][0],res[0][1],res[0][2],res[0][3])

                plt.plot(x,y)
                plt.plot(xt,yt,'r')

                plt.show()

            coeffs = np.append(coeffs,res[0],axis=0)
        warnings.filterwarnings('ignore',category=np.VisibleDeprecationWarning)