Location>code7788 >text

Chien Ka Ming's second assignment

Popularity:983 ℃/2024-10-27 00:09:43
Which course does this assignment belong to? /campus/zjlg/rjjc/
The goal of this assignment Implement a command line text counting statistics program, can correctly count the number of characters in the imported txt text, the number of words and other data
Name - School Number Chien Ka Ming 2022330361017

Description:

Due to the blog garden and gitee present the layout effect is not the same, this side first show, code cloud address attached at the end.

I. Functionality

① Basic Function: Implement a command line text counting program. Can correctly count the number of characters, words and sentences in the imported plain English txt text.

② expansion function: statistics on lines of code, blank lines, comment lines , etc., and provide the corresponding command interface.

③ Unit testing and performance testing

II. Detailed methods of use

1. Right clickcommencement icon, and in the search bar, typecmd


2.Download PyInstallerand put the Python scriptask for a doggy bag (at a restaurant)be all rightexeexecutable file
Enter the following code to install

pip install pyinstaller

After that, enter the following code to package the v0.2 Python script (the "D:\python code\v0." is the location of the Python file I saved)

pyinstaller --onefile "D:\python code\v0."

Enter the following code to package the v0.3 Python scripts

pyinstaller --onefile "D:\python code\v0."

Upon success, you can add a new file to the C drive'sdistfolder to find the generatedexefile
After that, I'll take the generatedexeThe files are moved to a folder named python code on the D drive.

3.Switch to the target directory at the root of the command line
Re-enter the start icon in the search bar and typecmdOpen it, and since my files are downloaded on the D drive, they need to beSwitch to D driveThe following are the commands to be used

cd /
D:
cd D:python code


3.Using Commands
Basic Function Command Mode:

v0. - <command> <file>.

instruction sheet

command descriptive
v0. -c <file> Counts and displays the number of characters in the specified file 📋
v0. -w <file> Counts and displays the number of words in the specified file 📝
v0. -s <file> Counts and displays the number of sentences in the specified file 💬

Expanded Function Command Mode:

v0. - <command> <file>.

instruction sheet

command descriptive
v0. -d <file> Calculate and display the number of lines of code 📜
v0. -e <file> Calculate and display the number of blank lines ⬜
v0. -n <file> Calculate and display the number of comment lines 🗒️

III. Results of the operation of basic functions

Text content:

Case 1:

v0. -c "Qian Xuesen "

(Since the filename hasblank spaceYou need to add the name of the file to the" "
 The results are as follows:

Case 2:

v0. -w "Qian Xuesen "

The results are as follows:

Case 3:

v0. -s "Qian Xuesen "

The results are as follows:

IV. Operational results of expanded functions

Code Content:

Case 1:

v0. -d "test material.py"

The results are as follows:

Case 2:

v0. -e "test material.py"

The results are as follows:

Case 3:

v0. -n "test material.py"

The results are as follows:

V. Unit testing

1. Basic Tests

The files test_v02.py and test_v03.py are unit test files that I wrote specifically for unit testing, and the following is the simple material it uses for unit testing for unit testing
v02 Test Content:

v02 The results are as follows:

v03 Test Content:

v03 The results are as follows:

2. Exception catching

v0.2Exception Capture: In the v0.2 code, enternon-existentThe filename of the file will be displayedError: File does not exist
importationnon-existentThe name of the file (abcde)
The results are as follows:

v0.3Exception Capture: In the v0.3 code, enternon-existentThe filename of the file will be displayedFile does not exist
importationnon-existentThe name of the file (abcde)
The results are as follows:

3.Wrong command display correct command usage

Error command on input in v0.2v0. -f <file>
The results are as follows:

Error command on input in v0.3v0. -z <file>
The results are as follows:

VI. Performance testing

Since the version of pycharm I downloaded seems to be a bit incompatible with the version of python, and the required imp module has been deprecated in newer versions of python, and you can't use the tools that come with the IDE to perform a performance test, I used Python's cProfile module in pycharm to perform a performance test analysis
The results are as follows:

VII. Sense of homework

This was a small programming assignment, but it took me a lot of time. I spent a lot of time at the school games and on the weekends checking out information and encountering many programming problems. When I encountered a problem, I might get stuck and couldn't come up with a solution even after thinking for a long time. After that, I found some useful information by checking Gitee and some open source materials on CSDN, and their experience gave me a lot of guidance, and then let me solve the problem smoothly, thanks to their open source spirit. After I solved the problem, I still feel a sense of accomplishment and a sense of joy and relaxation after solving the problem. I hope that I can persevere in my future research and strengthen my resilience.

Code Cloud Address./Qian_JM/qjm