Flask源码解析:字符串方法endswith与os.path.splittext()
Posted bad-robot
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Flask源码解析:字符串方法endswith与os.path.splittext()相关的知识,希望对你有一定的参考价值。
1、字符串方法endswith
endswith方法:
def endswith(self, suffix, start=None, end=None): # real signature unknown; restored from __doc__ """ S.endswith(suffix[, start[, end]]) -> bool Return True if S ends with the specified suffix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. suffix can also be a tuple of strings to try. """ return False
其中suffix支持字符串构成的元组(tuple)。
filename = "1.html" filename = "1.xml" # def endswith(self, suffix, start=None, end=None): # suffix can also be a tuple of strings to try. r = filename.endswith((‘.html‘, ‘.htm‘, ‘.xml‘, ‘.xhtml‘)) print(r)
输出结果为:False
2、os.path.splittext
import os fn = "F:/2018/python/review/project/Flask_01/__get__与__set__.py" # os.path.splitext # f: __get__与__set__.py f = os.path.basename(fn) print(f) # r: (‘__get__与__set__‘, ‘.py‘) r = os.path.splitext(f) print(r) # os.path.split dirname,filename=os.path.split(‘/home/ubuntu/python_coding/split_func/split_function.py‘) # dirname: /home/ubuntu/python_coding/split_func # filename: split_function.py print(dirname, filename)
os.path.splittext():将文件名和扩展名分开,返回由文件名和扩展名构成的元组
os.path.split():返回文件的路径和文件名构成的元组
以上是关于Flask源码解析:字符串方法endswith与os.path.splittext()的主要内容,如果未能解决你的问题,请参考以下文章