import pefile def is_pe_file(file_path): try: pe = pefile.PE(file_path) return True except pefile.PEFormatError: return False if __name__ == '__main__': file_path = r'C:\Users\Administrator\Desktop\大规模复杂软件无效样本清洗\demo1\Test - 副本\新建 文本文档 (2).txt' if is_pe_file(file_path): print('The file is a PE file') else: print('The file is not a PE file')