-1

In python, I am having a file read then trying to convert everything to lower case but it isn't changing. What am I doing wrong?

fstor = open(txt)
story = fstor.read()
story.lower()

OUTPUT ( I cleaned up punctuations and other marks )

The days went by and the wisest little pig's house took shape brick by brick From time to time his brothers visited him saying with a chuckle Why are you working so hard Why don't you come and play But the stubborn bricklayer pig just said no I shall finish my house first It must be solid and sturdy And then I'll

2 Answers2

0

Strings are immutable in python

fstor = open("file.txt")
story = fstor.read()
#story.lower() #strings are immutable in python
data = story.lower() #return a new string with lowercase
print(data)

Output:

the days went by and the wisest little pig's house took shape brick by brick from time to time his brothers visited him saying with a chuckle why are you working so hard why don't you come and play but the stubborn bricklayer pig just said no i shall finish my house first it must be solid and sturdy and then i'll

Write the data to another file

with open("file.txt") as fstor:
    story = fstor.read()
    data = story.lower() #return a new string with lowercase

    with open('another_file.txt','w') as afile:
        afile.write(data)
Udesh
  • 2,415
  • 2
  • 22
  • 32
0
with open('directory_path.txt', 'r') as f: 
    text = f.read() 
 
text = text.lower()
print(text)

works this code :)