def read_image(file):
image = imread(file)
return image
在这种情况下,我acept 文件是一个路径或图像数组,我该如何注释文件?
def read_image(file: str|array):
这可能吗?
更新
现在它起作用了。
以下@iggy12345
from typing import Union
def read_image(file: Union[str, list]):
.....
你需要做的是使用union
这允许您指定参数具有多种类型,例如
from typing import union
def read_image(file: union[str, list]):
pass
有关使用联合的更多信息,请参阅此处