摘要:本文主要向大家介绍了 C/C++知识点之Python写的C/C++代码比较,通过具体的内容向大家展示,希望对大家学习C/C++知识点有所帮助。
本文主要向大家介绍了 C/C++知识点之Python写的C/C++代码比较,通过具体的内容向大家展示,希望对大家学习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}\n","",mark)
8 mark = re.sub("#.{1,1000}\n","",mark)
9 return mark
10
11 def erase_space(args):
12 space = args.replace(" ","")
13 space = space.replace("\n","")
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()
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标编程语言C/C+频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号