# To read and write from a file
str = input("Enter file name to open : ")
while(True):
print("Choose one option : ")
print("1. Write to file.")
print("2. Read from file")
print("e. exit")
op = input();
if op == '1':
file = open(str+".txt","w")
ele = input("Enter a string to write to file : ")
file.write(ele+" ")
file.close()
elif op =='2':
try:
file = open(str+".txt","r")
fd = file.read()
print("file data : ")
print(fd)
file.close()
except (FileNotFoundError):
print("File not found.")
elif op == 'e':
break
else:
print("Choose correct option.")
If you have a great ability of thinking, imagination and visualisation than you have to codes your thinking and visualisation.
Friday, 15 June 2018
To read and write from a file using python programmin.
Subscribe to:
Post Comments (Atom)
Featured post
To add 'ing' at the end of a given string (length should be at least 3). If the given string already ends with 'ing' then add 'ly' instead. If the string length of the given string is less than 3, leave it unchanged. <br/>Sample String : 'abc' <br/> Expected Result : 'abcing' <br/> Sample String : 'string'
#To add 'ing' at the end of a given string (length should be at least 3). If the #given string already ends with 'ing' then...
Popular Posts
-
#To add 'ing' at the end of a given string (length should be at least 3). If the #given string already ends with 'ing'...
-
# Write a program that accepts a comma separated sequence of words as input # and prints the words in a comma-separated sequence after...
-
# To implement Queue using list queueList = [] def enQueue(ele='\0'): if ele!='\0': queueList.append(...
No comments:
Post a Comment