Delete a character in python. delete a character in python.

Source: Internet
Author: User

Delete a character in python. delete a character in python.

It is very troublesome to remove a character from the text using python. Different environments can use a variety of methods, such as regular expressions and del syntax. Now it is a simple and easy method to release, when this character is encountered, the system jumps over and does not operate on it. The function of deleting the character is perfectly displayed.

Test text jb51.txt

Http://www.bkjia.com/article/1.htm

Python code

#-*-Coding: UTF-8-*-def delblankline (infile, outfile): infopen = open (infile, 'R', encoding = "UTF-8 ") # open the ontology file outfopen = open (outfile, 'w', encoding = "UTF-8") # open the Writing File lines = infopen. readlines () for line in lines: # Read by row for db in line: # Read by word if db = '/': continue outfopen. write (db) # write the file infopen. close () # close the file outfopen. close () # close the file delblankline ("jb51.txt", "04.txt") # Call the Function

Shows the effect.

Is to remove the/in the string, you can replace it with your own OK as needed

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.