try: import cPickle as pickle except ImportError: import pickle class FeatureVector: def __init__(self): self.features = [] self.activefeatures = [] self.classification = None # set which features are active using a binary list # ex: For 2nd, 4th and 5th features to be active, pass [0,1,0,1,1] def setFeatures(self, binlist): activefeatures = [] if len(binlist) != len(self.features): print("Feature choice list must equal length of feature list") for b in range(len(binlist)): if binlist[b] == 1: activefeatures.append(self.features[b]) self.activefeatures = activefeatures def __repr__(self): return str(self.features) def writePickledData(filename): v = FeatureVector() v.features = [1, 2, 3, 4] v.activefeatures = [1, 2, 3, 4] vs = [v,v] with open(filename, 'wb') as file: pickle.dump(vs, file) def readPickledData(filename): with open(filename, 'rb') as file: x = pickle.load(file) # print(x) return x def main(): fv = FeatureVector() writePickledData("test.bin") readPickledData("test.txt") if __name__ == '__main__': main()