Python写的C/C++代码比较

Posted royaladd

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python写的C/C++代码比较相关的知识,希望对你有一定的参考价值。

 1 import sys
 2 import re
 3 
 4 # argv 是个列表,内容是文件的路径
 5 def erase_mark(args):
 6     mark = re.sub("//*.{1,1000}/*/","",args)
 7     mark = re.sub("//.{1,1000}
","",mark)
 8     mark = re.sub("#.{1,1000}
","",mark)
 9     return mark
10 
11 def erase_space(args):
12     space = args.replace(" ","")
13     space = space.replace("
","")
14     return space
15 
16 def show_different(args_one,args_two):
17     info = "[decument one: %s decument two: %s]" % (args_one,args_two)
18     print(info)
19 
20 
21 def display(information,condition):
22     if condition:
23         print(information[0])
24     else:
25         print(information[1])
26 
27 
28 def compare_same(args_one,args_two):
29     cycle = args_one if len(args_one) < len(args_two) else args_two
30     for i in range(len(cycle)):
31         if args_one[i] != args_two[i]:
32             show_different(args_one[i],args_two[i])
33     display(["decument is alike","decument is different"], args_one == args_two)
34 
35 
36 def achieve(args):
37     cover = open(args["decument_one"], mode = "r", encoding = "utf-8")
38     primary = open(args["decument_two"], mode = "r", encoding = "utf-8")
39     cover_info, primary_info = cover.read(), primary.read()
40     cover_info, primary_info = erase_mark(cover_info), erase_mark(primary_info)
41     cover_info, primary_info = erase_space(cover_info), erase_space(primary_info)
42     compare_same(cover_info, primary_info)
43 
44 
45 def main():
46     if len(sys.argv) < 3:
47         first_file,second_file = input("decoment one path:").strip(), input("decoment two path:").strip()
48     else:
49         first_file,second_file = sys.argv[1],sys.argv[2];
50     args = {"decument_one":first_file,"decument_two":second_file};
51     achieve(args)
52 
53 
54 if __name__ == "__main__":
55     main()

 

以上是关于Python写的C/C++代码比较的主要内容,如果未能解决你的问题,请参考以下文章

activemqrabbitmqkafka原理和比较

[linux][c/c++]代码片段01

[linux][c/c++]代码片段02

如何让python调用C和C++代码

[Python]常用代码块

牛逼!用 AI 实现 C++JavaPython 代码互译!