This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: filecmp is not working for UTF-8 BOM file.
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eryksun, paul.moore, steve.dower, suresh, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2021-02-09 05:36 by suresh, last changed 2022-04-11 14:59 by admin. This issue is now closed.

File name Uploaded Description Edit
source.txt suresh, 2021-02-09 05:36 source file/destination file suresh, 2021-02-12 06:41 source file/destination file
Repositories containing patches
Messages (7)
msg386692 - (view) Author: suresh (suresh) Date: 2021-02-09 05:36
Python base package filecmp is not working properly for 'UTF-8 BOM' css files.
I am using python version 3.6 and windows 10 OS.

while running the below code getting as False always.However the file content are same.

Code :

import filecmp
msg386745 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2021-02-09 20:50
I think you copy-pasted that code snippet incorrectly, because it has mismatched quotes.

Can you paste the correct code?

Also, please attach both files that are not comparing equal, ideally in a ZIP file (to avoid any modifications in transit), so that we can reproduce the issue.
msg386852 - (view) Author: suresh (suresh) Date: 2021-02-12 06:41
Please find the below Code and attached the files, expecting true as output and getting as false: 

"import filecmp



msg387086 - (view) Author: suresh (suresh) Date: 2021-02-16 04:52
Dear Team,

  Any more details are required. Kindly let me know.
msg387101 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2021-02-16 10:13
The two files in "" have the same contents:

    >>> open('source.css', 'rb').read() == open('destination.css', 'rb').read()

Maybe there's something peculiar about the stat results. Check that they're both reported as regular files with the same size:

    import os
    for f in ('source.css', 'destination.css'):
        print(f, os.path.isfile(f), os.path.getsize(f))
msg387301 - (view) Author: suresh (suresh) Date: 2021-02-19 10:29
I am getting same file size and are regular files (True) as below.

Could you assist on filecmp any changes required in passing the inputs. Since it returns false.


>>> os.chdir(r'C:\Users\suresh.n\Files')
>>> open('source.css', 'rb').read() == open('destination.css','rb').read()
>>> for f in ('source.css', 'destination.css'):
...         print(f, os.path.isfile(f), os.path.getsize(f))

source.css True 37465
destination.css True 37465
msg389054 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2021-03-19 05:38
I'm closing this as not a bug. You showed that all of the criteria used in a non-shallow comparison are the same on your end, i.e. they're both regular files with the same reported size and the same contents. Something is going on, which is a mystery, but it's not a bug in os.stat() or filecmp.
Date User Action Args
2022-04-11 14:59:41adminsetgithub: 87341
2021-03-19 05:38:28eryksunsetstatus: open -> closed
resolution: not a bug
messages: + msg389054

stage: resolved
2021-02-19 10:29:44sureshsetmessages: + msg387301
2021-02-16 10:13:58eryksunsetnosy: + eryksun
messages: + msg387101
2021-02-16 04:52:30sureshsetmessages: + msg387086
2021-02-12 06:41:46sureshsetfiles: +
hgrepos: + hgrepo398
messages: + msg386852
2021-02-09 20:50:25steve.dowersetmessages: + msg386745
components: + Library (Lib), - Windows
2021-02-09 05:36:37sureshcreate