Python Practice Path 4--Implementation progress bar and file content parameter substitution

Source: Internet
Author: User

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

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.