Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在解析一个用 UTF16-LE 编写的文件以进行相当简单的匹配,但它们似乎都没有触发。例如,我有以下代码。
with open(filepath) as f: for line in f: if 'TEST_CASE' in line: print(line)
有没有一种好方法可以在不更改文件本身的情况下检查文件中的行是否匹配?
根据我的评论codecs.open('filename', encoding='utf-16-le')
codecs.open('filename', encoding='utf-16-le')