Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to compare whether the contents of two files are the same in python

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

What this article shares to you is about how to compare the contents of the two files in python is the same, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article. Without saying much, follow the editor to have a look.

Import os

Def cmp_file (F1, f2):

St1 = os.stat (F1)

St2 = os.stat (f2)

# compare file sizes

If st1.st_size! = st2.st_size:

Return False

Bufsize = 81024

With open (F1, 'rb') as fp1, open (f2,' rb') as fp2:

While True:

B1 = fp1.read (bufsize) # read data of specified size for comparison

B2 = fp2.read (bufsize)

If b1! = b2:

Return False

If not b1:

Return True

Print (cmp_file ('. / data/1.txt','. / data/2.txt'))

The above is how to compare the contents of the two files in python. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report