Sublime Forum

I want a (.PY) script that only save specific text letters

#1

This program takes input.txt
It has unwanted (1234567890) and so on.

It only saves these letters:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z

(space button)

(enter button) and (tab button) is converted to (space button)

Now collapse consecutive whitespaces into one space.

The others are removed.

Then the output.txt is created.

0 Likes

#2

Try this, untested and inefficient due to re but it should work:

import re

with open("input.txt", "r") as f:
    txt = f.read()

txt = re.sub(r"^A-Za-z]", '', txt)
txt = re.sub(r"\s+", " ", txt)

with open("output.txt", "w") as f:
    txt = f.write()
0 Likes