我有一些Pickled Python对象,我打算有条件地使用它。代码如下:
if(mode == 1):
scaler = joblib.load('all_scaler.pkl')
#Do stuff, create input variable
if(mode == 1):
scaledinput = scaler.transform(input)
如果我这样使用它,我当然会收到错误variable used before assignment
。如果我这样做:
scaler = []
if(mode == 1):
scaler = joblib.load('all_scaler.pkl')
#Do stuff, create input variable
if(mode == 1):
scaledinput = scaler.transform(input)
我收到错误list object has no function called transform
。我认为Python会动态分配对象类型,但似乎不是这样......我怎么能这样正确呢?