Python endswith()反向?
我正在使用win32com.client来读取一个Excel文件,我想find一切不以“some string”结尾的值(s)我有:
ws.Cells(i, 8).Value
由于我不知道endswith()的解决方法,我也试图通过也可以做这项工作的值的长度进行search,但我不能在ws.Cells(i,8).Value上调用len(),因为我得到'unicode'错误。 我也尝试将值转换为一个string,但没有运气。
基本上我想这样做:
if len(ws.Cells(i, 8).Value) > 255: ws.Cells(i, 8).Value = ws.Cells(i, 8).Value + " (Issues Here)"
我感谢我能得到的任何支持。
只是not
在if语句中使用。
string_list = ["this ends in some string", "this string does not"] for string in string_list: if not string.endswith('some string'): print string, ". GOOD!"
结果:
this string does not. GOOD!