File Handling. Get data from Screen and Write to a file in Write and Append Mode.
In this we open the file in Write Only Mode and save the data to file. In readonly mode only one line is writte to a file. We can use ‘a’ append mode to append line to same file.
#Clear Screen
import os
os.system('cls')
#Input data from Screen as Name age and Salary.
name=raw_input("Enter Name : ")
age =raw_input("Enter Age : ")
sal =raw_input("Enter Salary: ")
#Open file in Write mode Only ‘r’ and Append Mode ‘a’.
w_file=open("person.txt","a")
w_file.write(name+","+age+","+sal+'\n')
w_file.close()
No comments:
Post a Comment