可以同时过滤多种开头和结尾:
if __name__ == '__main__':
aaaa = 'rtsp://aaaaaaaaa'
bbbb = 'rtmp://aaaabbbb'
datas=[aaaa,bbbb]
for data in datas:
if data.startswith(('rtsp://', 'rtmp://', 'http://', 'https://')):
print("start with")
if data.endswith(('aaaa', 'bbbb', 'http://', 'https://')):
print("end with")
以前的方法:
extensions = ['.jpeg', '.jpg', '.png', '.bmp']
images = []
for root, dirs, files in os.walk(folderPath):
for file in files:
if file.lower().endswith(tuple(extensions)):
relativePath = os.path.join(root, file)
path = ustr(os.path.abspath(relativePath))
images.append(path)
images.sort(key=lambda x: x.lower())
return images