获取文件名后缀
1. splittext()方法
os.path.splittext(path)[-1]
2. re正则方法
file_name = "aaaa.pdf"
suffix_str = str(re.search('\w*(.\w*)', file_name).group(1))
3. split方法切割
这种只是拿到了py没有点,所以再加上点也是可以的
path = "test.py"
suffix = path.split(".")[1]
print("suffix: {}".format(suffix))