Title: filecmp is not working for UTF-8 BOM file.
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.6
Status: open Resolution:
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 2021-02-19 10:29 by suresh.

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 (6)
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
Date User Action Args
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