1. Document Progress bar
Code Requirements:
Visualize and increase the number of #的功能.
Code implementation:
1 #! /user/bin/env Ptyhon2 #-*-coding:utf-8-*-3 #Author:visonwong4 5 ImportSys,time6 forIinchRange (20):7Sys.stdout.write ("#")8 Sys.stdout.flush ()9Time.sleep (0.2)
Output Result:
1 E:\Python\PythonLearing\venv\Scripts\python.exe e:/python/pythonlearing/ progress bar. PY2 ####################
There will be an animated effect of increasing #.
2, file content parameter replacement
Code Requirements:
Replace the contents of the file by running the appropriate method, entering the replacement content and the replaced content
1 #! /user/bin/env Ptyhon2 #-*-coding:utf-8-*-3 #Author:visonwong4 5 fromSysImportargv6 7Script,find_str,replace_str =argv8 9f = open ('Yesterday.txt','R', encoding='Utf-8')TenF1 = open ('Yesterday_bak.txt','W', encoding='Utf-8') One A - forLineinchF: - ifFind_strinchLine : theline =line.replace (FIND_STR,REPLACE_STR) - F1.write (line) - - f.close () +F1.close ()
Output Result:
At run time, enter at the command line:
Python changefile.py Young Old
Original file content:
1 Oh, yesterday when I am young2 Oh yesterday when I was young and crazy3 so many, many songs were waiting to be sung4 There are so many sweet longtaisheng waiting for me to sing5So many wild pleasures layinchStore forMe6 There are so many wanton pleasures waiting for me to enjoy7 And so much pain my eyes refused to see8 there's so much pain in my eyes I can't seem to ignore9There is so many songsinchMe that won't be sungTen I've got so many songs that I'll Never be sung One I feel the bitter taste of tears upon my tongue A I tasted the bitter taste of the tongue's tears -The time has come forMe to pay forYesterday - It's time to pay the price for yesterday the When I am Young -When I was young and crazy
Modified file content:
1 Oh, yesterday when I am old2 Oh yesterday when I was young and crazy3 so many, many songs were waiting to be sung4 There are so many sweet longtaisheng waiting for me to sing5So many wild pleasures layinchStore forMe6 There are so many wanton pleasures waiting for me to enjoy7 And so much pain my eyes refused to see8 there's so much pain in my eyes I can't seem to ignore9There is so many songsinchMe that won't be sungTen I've got so many songs that I'll Never be sung One I feel the bitter taste of tears upon my tongue A I tasted the bitter taste of the tongue's tears -The time has come forMe to pay forYesterday - It's time to pay the price for yesterday the When I am Old -When I was young and crazy
Python Practice Path 4--Implementation progress bar and file content parameter substitution