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