# Open,read,write on text file
f=open("Sample text","r") #open the file in read mode
f=open("Sample text","w") #open the file in write mode
f=open("Sample text","a") #open the file in appending mode
f=open("Sample text","+") #open the file in updating mode
f=open("Sample text","rb") #open the file in binary mode
f=open("Sample text","rt") #open the file in text mode
with open("sample.txt") as f: #best way open and auto close file
text=f.read() #read its contents
print(text) #print its contents
f.close() #close the file
# Program to read line by line from a text file
f = open('sample.txt')
# read first line
data = f.readline()
print (data)
# Read second line
data = f.readline()
print(data)
# Read Third line
data = f.readline()
print(data)
f.close()
# Program to read the text from a given file anf find out wheater it
contains the word or not
# f=open("file.txt") #not working(vikas use pycharm)
f=open(r"G:\My Drive\Coding\Python\Start\file.txt")
t=f.read()
w=input("Enter Word to find in text tile : ")
if w in t:
print("Word Found")
else:
print("Not Found")
f.close()
# Program to