Skip to content

Codes #576

@Sumeetgaikwad27

Description

@Sumeetgaikwad27

'''f=open("E:\Samplefile.txt","w")
f.write("Sanika") # overwrite the entire file
f.write("Sumeet \nGaikwad")

f=open("E:\Samplefile.txt","a")
f.write("Sumeet \nGaikwad") #adds to the file along with keeping existing data'''

#write in file and print all content from begining of the file
f=open("E:\Practice.txt","w+")
f.write("Hi everyone\n")
f.write("we are learning file I/O\n")
f.write("using java\n")
f.write("I like programming in java\n")
f.seek(0) #move cursor to beginning
data=f.read()
print(data)

#replace a word in a file
new_data=data.replace("java","python")
print(new_data)
with open("E:\Practice.txt","w+") as f:
f.write(new_data)

word=("learning")
with (open("E:\Practice.txt","r")) as f:
content=f.read()
if(content.find(word)!=-1):
print("found")
else:
print("not found")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions