Python achieves 2 file comparisons

Source: Internet
Author: User

Compare one of the 2 files in Python without the content

#!/usr/bin/env python

#coding: UTF8

def file (file_name):

Filea_list,fileb_list = [],[]

Filea_name,fileb_name = File_name.split ()

With open (Filea_name) as FA:

For line in Fa.readlines ():

Filea_list.append (Line.split ())

With open (Fileb_name) as FB:

For line in Fb.readlines ():

Fileb_list.append (Line.split ())

Return filea_list,fileb_list

def func ():

filea_list,fileb_list = File (file_name)

If Len (filea_list) > Len (fileb_list):

For line in Fileb_list:

Filea_list.remove (line)

Print Filea_list

Else

For line in Filea_list:

Fileb_list.remove (line)

Print Fileb_list

If __name__== ' __main__ ':

print "Input" files "

file_name = Raw_input ("Enter The other files you need to compare:")

Func ()

Attached source code:

Also have EXE format can be executed under Windows but only in English Chinese is not able to execute

Python achieves 2 file comparisons

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.