Python寫的C/C++代碼比較

來源:互聯網
上載者:User

標籤:file   mod   alike   mat   main   ++   c++   style   sys.argv   

 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 mark10 11 def erase_space(args):12     space = args.replace(" ","")13     space = space.replace("\n","")14     return space15 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_two30     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++代碼比較

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.