[Solved] Writing only lower case letters to file in Python


Code

input_f = input("Enter the file name to read from: ")
output_f = input("Enter the file name to write to... ")

fw = open(output_f, "w")

with open(input_f) as fo:
    for w in fo:
        for c in w: 
            if c.isalpha():
                fw.write(c.lower())
            if c.isspace():
                fw.write('\n')

fo.close()
fw.close()

input.txt

HELLO
12345
WORLD
67890
UTRECHT
030
dafsf434ffewr354tfffff44344fsfsd89087uefwerwe

output.txt

hello

world

utrecht

dafsfffewrtffffffsfsduefwerwe

Sources

  1. How to convert string to lowercase in Python?

  2. http://www.tutorialspoint.com/python/file_readlines.htm

  3. http://www.pythonforbeginners.com/files/reading-and-writing-files-in-python

  4. How to read a single character at a time from a file in Python?

  5. How to check if text is “empty” (spaces, tabs, newlines) in Python?

solved Writing only lower case letters to file in Python