I am trying to write a python script to format SQL codes for better readability.
eg. converting specific lowercase words to uppercase: select -> SELECT
I am trying to do this using the reading and writing function in Python. However, I am stuck. Here is my code:
words = ['select', 'from', 'where']
w = open('03_TextUpper.txt', 'w')
with open('03_TextLower.txt', 'r') as file:
for line in file:
for word in line.split():
if word in words:
w.write( word.upper() )
w.write( line )
This prints out the uppercase of the specific words, but does not remove the lowercase words.
Is there a better way of writing this in Python?