Reading files

reading what are inputted in files

we can input text files, image files, docx files and more!

filesinpy.png

read1 = open('python folder/read.txt')
read2 = read1.read()

print(read2)

prints, (as this line is in the other text file)

Hi, This is Shafni From Sri Lanka

And I am 17years old

read1 = open('python folder/read.txt')
read2 = read1.read()

print(read2)
read1.close() #after we are done we shud close the file, it is good to close

prints, (first line and the more we print the next lines by line will be printed)

Hi, This is Shafni From Sri Lanka

read1 = open('python folder/read.txt')
read2 = read1.readlines()

print(read2)
read1.close()

we can use readlines()

prints in lists,

['Hi, This is Shafni From Sri Lanka \\n', 'And I am 17years old']

Writing Files