Python, How to use the @ in class method
我尝试在类方法中使用
1 2 3 4 | class Dataset: @parse_func def get_next_batch(self): return self.generator.__next__() |
解析函数如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 | def parse_func(load_batch): def wrapper(**para): batch_files_path, batch_masks_path, batch_label = load_batch(**para) batch_images = [] batch_masks = [] for (file_path, mask_path) in zip(batch_files_path, batch_masks_path): image = cv2.imread(file_path) mask = cv2.imread(mask_path) batch_images.append(image) batch_masks.append(mask) return np.asarray(batch_images, np.float32), np.asarray(batch_masks, np.uint8), batch_label return wrapper |
但是,当我给
Traceback (most recent call last):
TypeError: wrapper() takes exactly 0 arguments (1 given)
你知道为什么会出现这个错误和任何解决方案吗?非常感谢你!
函数
您可以编辑到
只是简单的改变
1 2 3 4 5 6 7 8 9 10 11 12 13 | def parse_func(load_batch): def wrapper(*para): batch_files_path, batch_masks_path, batch_label = load_batch(*para) batch_images = [] batch_masks = [] for (file_path, mask_path) in zip(batch_files_path, batch_masks_path): image = cv2.imread(file_path) mask = cv2.imread(mask_path) batch_images.append(image) batch_masks.append(mask) return np.asarray(batch_images, np.float32), np.asarray(batch_masks, np.uint8), batch_label return wrapper() |