Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中,如何检查文件名是否以';结尾;。html';或'_文件';?_Python_Html - Fatal编程技术网

在python中,如何检查文件名是否以';结尾;。html';或'_文件';?

在python中,如何检查文件名是否以';结尾;。html';或'_文件';?,python,html,Python,Html,在python中,如何检查文件名是否以“.html”或“_files”结尾?您可能想知道文件名是否以这些字符串结尾,而不是文件本身: if file_name.endswith((".html", "_files")): # whatever 要测试文件是否以这些字符串之一结尾,可以执行以下操作: with open(file_name) as f: f.seek(-6, 2) # only read the last 6 characters of the

在python中,如何检查文件名是否以“.html”或“_files”结尾?

您可能想知道文件名是否以这些字符串结尾,而不是文件本身:

if file_name.endswith((".html", "_files")):
    # whatever
要测试文件是否以这些字符串之一结尾,可以执行以下操作:

with open(file_name) as f:
    f.seek(-6, 2)           # only read the last 6 characters of the file
    if f.read().endswith((".html", "_files")):
        # whatever

你的意思是如果文件名以
.html
\u files
结尾吗?是的,这就是我的意思,对不起,我英语说得不太好