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.

classification
Title: filecmp is not working for UTF-8 BOM file.
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
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.

Files
File name Uploaded Description Edit
source.txt suresh, 2021-02-09 05:36 source file/destination file
files.zip 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
filecmp.clear_cache()
boolfile=filecmp.cmp(r'C:\Users\suresh.n\python\RPA\Page\Sowmiya\downloads\destination.txt',r'C:\Users\suresh.n\python\RPA\Page\Sowmiya\source\source,r'C:\Users\suresh.n\python\RPA\Page\Sowmiya\downloads.txt',shallow=False)
print(boolfile)
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

filecmp.clear_cache()

boolfile=filecmp.cmp(r'C:\destination.css',r'C:\source.css',shallow=False)

print(boolfile)"
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 "files.zip" have the same contents:

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

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.

Code: 

>>> os.chdir(r'C:\Users\suresh.n\Files')
>>> open('source.css', 'rb').read() == open('destination.css','rb').read()
True
>>> 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.
History
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: + files.zip
hgrepos: + hgrepo398
messages: + msg386852
2021-02-09 20:50:25steve.dowersetmessages: + msg386745
components: + Library (Lib), - Windows
2021-02-09 05:36:37sureshcreate