码迷,mamicode.com
首页 > 编程语言 > 详细

python开发文本文件对比

时间:2017-02-16 14:30:21      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:ted   root   ica   else   div   state   rac   read   split   

技术分享
 1 #coding:utf-8
 2 #!/usr/bin/python
 3 from difflib import *
 4 import sys
 5 import os
 6 reload(sys)
 7 sys.setdefaultencoding( "utf-8" )
 8 from Tkinter import *
 9 import tkFileDialog;
10 import tkMessageBox;
11 
12 root=Tk();
13 root.geometry("280x300+983+630");
14 root.attributes("-alpha",1)
15 root.attributes("-topmost",1);
16 root.title=("Contrast");
17 
18 filename2 = tkFileDialog.askopenfilename(initialdir = C:\Python);
19 label1=Label(root,text=filename2); 
20 label1.pack();
21 
22 filename4 = tkFileDialog.askopenfilename(initialdir = C:\Python);
23 label2=Label(root,text=filename4); 
24 label2.pack();
25 
26 def diffcommand(filename):
27     fileHandle = open(filename,"rb")
28     text=fileHandle.read().splitlines()
29     fileHandle.close()
30     return text
31 
32 def diffbtn():
33     if filename2=="" or filename4=="":
34         tkMessageBox.showinfo("Sorry","Please select file")
35     else:
36         text1_lines=diffcommand(filename2)
37         text2_lines=diffcommand(filename4)
38         s=HtmlDiff.make_file(HtmlDiff(),text1_lines,text2_lines)
39         f=open(r"c:\对比结果.html",w)
40         f.write(s)
41         f.close()
42 
43 Button(root,text="Contrast",state=ACTIVE,bg="blue",command=diffbtn).pack(side=LEFT)
44 root.mainloop()
thinter

 

python开发文本文件对比

标签:ted   root   ica   else   div   state   rac   read   split   

原文地址:http://www.cnblogs.com/yuanshaoqian/p/6404729.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!