zoukankan      html  css  js  c++  java
  • python开发文本文件对比

     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环境变量的配置
    关于selenium+python的googledirver和iedirver的配置
    jdk1.6环境变量配置
    windows server 2012R2安装激活码
    Git生成SSHKey
    Linux下配置和安装VNCServer远程服务
    Win7 64位硬盘安装Ubuntu 64位的细微配置
    apache tomcat 8.0 显示目录文件
    跨域登录
    jsonp 代码优化
  • 原文地址:https://www.cnblogs.com/yuanshaoqian/p/6404729.html
Copyright © 2011-2022 走看看