码迷,mamicode.com
首页 > 其他好文 > 详细

Flask源码解析:字符串方法endswith与os.path.splittext()

时间:2018-12-04 10:11:25      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:real   ubuntu   set   sel   元组   bool   one   spl   with   

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()

标签:real   ubuntu   set   sel   元组   bool   one   spl   with   

原文地址:https://www.cnblogs.com/bad-robot/p/10062284.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!