Python 代码错误 'AttributeError: 'int' object has no attribute 'endswith'' 的解决方法
该错误的原因是源(source)是一个整数,而整数没有endswith方法。要解决此错误,可以使用str()函数将整数转换为字符串:
webcam = str(source).isnumeric() or str(source).endswith('.txt') or str(source).lower().startswith(('rtsp://', 'rtmp://', 'http://', 'https://'))
这样就可以避免源为整数时出现此错误。
原文地址: https://www.cveoy.top/t/topic/oG6M 著作权归作者所有。请勿转载和采集!