Python Learning Note: A simple example of Easygui

Source: Internet
Author: User

Learn the Python graphical user interface Easygui, turn a case example, the function is to count the number of lines of code under the specified folder, test the code you wrote to 100,000 lines is still how much distance

First paste the code, the code is not written by themselves, before their own code can not run, very embarrassing, beginners hurt, code to learn to understand the use of Easygui.

ImportEasygui as GImportOSdefShow_result (Start_dir): Lines=0 Total=0 Text=""     forIinchSource_list:lines=Source_list[i] Total+=lines Text+=""%s" source file%d, source code%d line \ n"%(i, file_list[i], lines) title='Statistical Results'msg='you have compiled a total of%d lines of code, complete the progress:%.2f%%\n 100,000 lines of code is still less than%d lines, please continue to work! '% (total, total/1000, 100000-Total ) G.textbox (msg, title, text)defCalc_code (file_name): Lines=0 with open (file_name) as F:Print('parsing file:%s ...'%file_name)Try:             forEach_lineinchF:lines+ = 1exceptUnicodedecodeerror:Pass #inevitably you will encounter files that are incompatible with the format, which is ignored here ...    returnLinesdefSearch_file (Start_dir): Os.chdir (Start_dir) forEach_fileinchOs.listdir (Os.curdir): Ext= Os.path.splitext (each_file) [1]        ifExtinchTarget:lines= Calc_code (Each_file)#number of rows of statistics            #Do you remember the unusual usage? If the dictionary does not exist and throws Keyerror, the dictionary key is added            #number of statistics files            Try: File_list[ext]+ = 1exceptKeyerror:file_list[ext]= 1#Count source code lines            Try: Source_list[ext]+=LinesexceptKeyerror:source_list[ext]=LinesifOs.path.isdir (each_file): Search_file (each_file)#Recursive invocationOs.chdir (Os.pardir)#remember to return to the previous level of the directory after a recursive callTarget= ['. C','. cpp','. PY','. CC','. CS','. Java','. Pas','. ASM']file_list={}source_list={}g.msgbox ("Please open the folder where you store all your code ...","Statistics Code Amount") path= G.diropenbox ("Please select your code base:") search_file (path) show_result (path)

Test procedures, write-down diagrams

Haha, do not be my code to scare, in fact, my Search Folder is I store a variety of Reference instance code folder, the program in Idle run an estimated three minutes.

Personal code volume but million, novice injured, slowly climb, slowly efforts ~

Python Learning Note: A simple example of Easygui

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.