Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am writing a python program to try to remove all special sentences between and all non-alphanumeric characters except space from a folder of txt
I am writing a python program to try to remove all special sentences between and all non-alphanumeric characters except space from a folder of txt 'UTF-16' encoded book files. however i am encountering problems, Below is my code.
import osfor path, dirs, files in os.walk("/Users/16258/Desktop/dataset/"): for f in files: filename = os.path.join(path, f) myBooks = open(filename, 'r', encoding='UTF-16')f = open('cleaned.txt', 'w', encoding='UTF-16')for files in myBooks: for line in files: start = line.startswith(') end = line.endswith('>') if not start: if not end: f.write(line)f.close()
the problem of this code is that the output only removes the "" characters but not the sentences with it. For example input is AAA, the output of my code is I love to study AAA instead of AAA. Also the code only reads 1 file from the folder somehow. Graphs are attached.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started