开发者

compare file contents using python [duplicate]

This question already has an answer here: 开发者_JAVA技巧 Closed 11 years ago.

Possible Duplicate:

comparing contents of two files using python

I have a file name globalexclusionlist.txt and i have contents in it like

      #include <stdio.h>
      #include <iostream>
      import subprocess
      import java.sql.*;import java.io.*;
      ruby library
      show tables; 

      ......and many more

I have another file named libraries.txt and the contents of this file are

     import mymodule
     import empmodule,os
     import subprocess
     import java.sql.*
     #include <stdio.h>
     #include <iostream>
     import datetime,logging,re
     import java.io.*;
     .......and many more

My question is that from python how to know that the contents which are in exclusionlist.txt is also present in libraries.txt since here it is jumbled up..

     f = open('globalexclusionlist.txt', 'r')
     f.read()

     f1= open('libraries.txt', 'r')
     f1.read()

    if (//Is contents of f1 present in f2):
         print libraries found
    else:
         print not found

    f.close()
    f1.close() 


Check out difflib

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜