zoukankan      html  css  js  c++  java
  • 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():返回文件的路径和文件名构成的元组

      

      

  • 相关阅读:
    jquery ajax全解析
    java 远程调试 remote java application
    w3c html dom
    ngx_php
    websocket+前后端分离+https的nginx配置
    CentOS6下基于Nginx搭建mp4/flv流媒体服务器
    nginx could not build the server_names_hash 解决方法
    Nginx 实现AJAX跨域请求
    Nginx与Apache的Rewrite规则的区别
    nginx支持pathinfo模式
  • 原文地址:https://www.cnblogs.com/bad-robot/p/10062284.html
Copyright © 2011-2022 走看看