- Python Syntax
- Python Environment
- Python Snippets
原来的 Python 变量是没有类型的,这个 Function Annotations 其实是为了规范函数中参数的类型,给调用者提供明显的注释,已在运行前对参数类型做出检查,免得运行时,报 ErrorValue 错误。除了 Function Annotations 外,还有一个检查变量类型的方法是 isinstance 方法。
7.3 给函数参数增加元信息 给出了一个最简单的例子
def add(x:int, y:int) -> int:
return x + y
冒号 :
后面是变量类型,箭头 ->
后面是返回的变量类型
from os import listdir
from os.path import isfile, join
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
from os import walk
f = []
for (dirpath, dirnames, filenames) in walk(mypath):
f.extend(filenames)
break
by How do I list all files of a directory?
import sys
sys.path.append('....')
from data.flir.detection import FLIRDetection
如果只是 parent, 那么可以用 from ..data.flir.detection import FLIRDetection